Using Excel functions in VBA

lukeshuttlewood

Board Regular
Joined
Jul 27, 2004
Messages
90
Hi,

Using the TODAY() function in an Excel spreadsheet cell at this moment in time would return something like 09/Nov/2005.

I want to know if it is possible to use excel functions in VBA without ever applying anything to the spreadsheet itself to get the return product.

I have tried this (below) in VBA.......I realy want to get just the 2 characters from the right of the product which would be = 05..............If it worked anyway!!!


ThisYear = Right("" & Application.WorksheetFunction.TODAY() & "", 2)

Does anyone know the syntax for this?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi Luke

You can do it like this:

ThisYear = EVALUATE("RIGHT(TEXT(TODAY()," & Chr(34) & "ddmmyy" & CHR(34) &"),2)")

or:

ThisYear = RIGHT(CSTR(EVALUATE("YEAR(TODAY())")),2)

Best regards

Richard
 
Upvote 0
VBA itself has many functions of its own, Date() being one of them. The worksheetfunction method supports only some XL functions, typically those missing from VB(A).

In your case Year(Date()) will do the job. No need for Evaluate(...)

lukeshuttlewood said:
Hi,

Using the TODAY() function in an Excel spreadsheet cell at this moment in time would return something like 09/Nov/2005.

I want to know if it is possible to use excel functions in VBA without ever applying anything to the spreadsheet itself to get the return product.

I have tried this (below) in VBA.......I realy want to get just the 2 characters from the right of the product which would be = 05..............If it worked anyway!!!


ThisYear = Right("" & Application.WorksheetFunction.TODAY() & "", 2)

Does anyone know the syntax for this?
 
Upvote 0

Forum statistics

Threads
1,203,670
Messages
6,056,666
Members
444,881
Latest member
Stu2407

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