Can this formula be put in a message box?

tim 105

New Member
Joined
Apr 26, 2004
Messages
31
Just find this site, lots of useful info here!

I can enter this MsgBox 5 + 5 and get 10 when I call the message box which works fine, but if I try this MsgBox DATEDIF(TODAY(), 40696, "y") & " years " & DATEDIF(TODAY(), 40696, "ym") & " months " & DATEDIF(TODAY(), 40696, "md") & " days"
I get compile error sub or function not defined, so can a formula like this be put in a message box? I can reference the cell with the formula like this, MsgBox Range("A1"), and it works but I would like to have it all in the message box if possible, Thanks Tim
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
A quick check of VBA help shows that DATDIF is not supported in VBA, even with application.worksheetfunction. There may be some way to get it to work but others will have to chime in as it is over my head. VBA offers the DATEDIFF (note the 2 F's) function but it is not going to be as clean as you want. You can check it out in the help system for VBA.
 
Upvote 0
Hi - welcome to the board.

Not sure what you are trying to do...

...is this what you are after?

MsgBox [A1].Formula
 
Upvote 0
I was going to mention what Seti did DateDiff(). Also, VBA has Date; it does not have Today() unless you access it via the collection of WS functions [application.worksheetfunctions.today()] The rest is just working out the math...
 
Upvote 0
Ok, so after looking at DateDiff I can use this,
MsgBox DateDiff("yyyy", Date, 40696) & " Years ", to get years, or months or days by changing yyyy to m or d , but being new to this VBA stuff I have no idea how, or if it can be done, to get it to show years, months and days like the formula in the cell shows, should be 7 years 1 months 7 days. Tried MsgBox DateDiff("yyyy", Now, 40696) & " Years " & DateDiff("m", Now, 40696) & " Months " & DateDiff("d", Now, 40696) & " Days ", but this gives 7 years 86 months 2593 days, if this can not be done I will just continue to reference the cell address. Thanks Tim
 
Upvote 0

Forum statistics

Threads
1,216,725
Messages
6,132,347
Members
449,719
Latest member
excel4mac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top