Application.WorksheetFunction(Now) getting error

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

I am using Excel 2003 with Windows XP on a network. I keep getting errors with some code. In a sheet, I have:

Sub GetUser()
Range("Created").Value = Application.WorksheetFunction(Now())
Range("Author").Value = Application.UserName
End Sub

The code for the Author works perfectly. The code for Created where it is suppose to get todays date, I get an error:

Run-Time error '438':
Object does not support this property or method

When I execute the code in break mode (run line by line), I hover my curosr over the Now element and do see it does contain todays date.

Does it make a difference if this code is in the sheet or in a module? I get the same errror whether the code is in either place.

What makes this worse is I swear it worked a week ago but not now. I have made many changes since. Weird but it must have been something I did.

Thanks,

GL
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
How about...

Code:
Sub GetUser()
Range("Created").Value = Now
Range("Created").Value = Application.UserName
End Sub

It shouldn't make a difference if you place the code in sheet module or in a module
 
Upvote 0
Once again, simplier is better.

Works: Range("Created").Value = Now

Doesn't work: Range("Created").Value = Application.WorksheetFunction(Now())

Thanks very much Jeffrey and Vog
 
Upvote 0
The VBA command "Now" has a precision of 1 second where the WorksheetFunction Now has millisecond precision. I ended up here from a google search trying to find how to call the worksheet function from VBA. One method is to use brackets like this:

Code:
[B]Range("Created").Value = [Now()][/B]

However, bracketed expressions cannot be validated at compile-time. This is why I was looking for a way to call the worksheet function using the application object instead of a bracketed call.
 
Upvote 0
A host-specific bracketed expression is only evaluated at runtime. This means that your code will compile and you might still get run-time errors.
I understand that... I guess my problem is trying to image the run-time error you think you might get if you use [NOW()], which always evaluates to a Double, in your code. Can you cite an example where you think using [NOW()] would cause a run-time error for you?
 
Upvote 0
The VBA command "Now" has a precision of 1 second where the WorksheetFunction Now has millisecond precision. I ended up here from a google search trying to find how to call the worksheet function from VBA...
Why not use the Timer function?
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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