If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > A Simple question.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-10, 14:29
atsukoarai86 atsukoarai86 is offline
Registered User
 
Join Date: Sep 2008
Location: NM, USA
Posts: 94
Question A Simple question.

Okay, be gentle. I am not a noob to VBA, but I AM a noob to using it with MS Excel.

There doesn't seem to be a built in function that can take two dates and tell me "there's x many years between them", so I was trying to do it in VBA. After just a few minutes I felt like I had just sunk from pro to drooling moron, because I realize I have no idea what I'm doing.

I know how to write a function, but...how um... How do I USE it?? How do I get the function I wrote from the VBA module into that cell that needs to do the calculatin'?
__________________
"Unix is user friendly... It's just very picky about its friends."

The best things in life...are well-documented.
Reply With Quote
  #2 (permalink)  
Old 06-04-10, 15:02
atsukoarai86 atsukoarai86 is offline
Registered User
 
Join Date: Sep 2008
Location: NM, USA
Posts: 94
Nevermind, I figured it out.
__________________
"Unix is user friendly... It's just very picky about its friends."

The best things in life...are well-documented.
Reply With Quote
  #3 (permalink)  
Old 06-04-10, 15:54
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi,

There are several ways to do it with native Excel worksheet functions.

For reference, there's a not very well known Excel worksheet function called DATEDIF(), which is not to be confused with the VBA function called DATEDIFF(). I believe only Excel 2000 helpfiles contain any information on it, which is why most users aren't familiar with it. To get x number of years between two dates you can use it like this:

=DATEDIF(A1,A2,"y")

where A1 contains the earlier date and A2 contains the later date.

For more information about the DATEDIF() worksheet function, have a look at Microsoft Excel MVP Chip Pearson's excellent article:
http://www.cpearson.com/excel/datedif.aspx


Hope that helps...
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On