ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Now Function Question (https://www.excelbanter.com/excel-programming/391891-now-function-question.html)

Nausett

Now Function Question
 
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word, Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub




Mark Lincoln

Now Function Question
 
To put the current date into B1, just do this:

Range("B1").Value = Date

In VBA, Date returns the current system date.

Mark Lincoln

On Jun 22, 4:23 pm, Nausett wrote:
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word, Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub




Rick Rothstein \(MVP - VB\)

Now Function Question
 
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word,
Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today
End Sub


Although I am not sure why VBA cares about it, the variable name "today" is
where your problem is. I'm guessing it is a reserved keyword for VBA inside
of Excel... change the variable name and your code should work fine (unless
you stumble upon another keyword, that is<g).

Rick


Michael

Now Function Question
 
Try this:
Sub Dateparttest()
Today = Now
Range("B1").Value = Today
Range("B1").NumberFormat = "mmmm"

End Sub







"Nausett" wrote:

I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word, Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub




Mark Lincoln

Now Function Question
 
On Jun 22, 4:33 pm, "Rick Rothstein \(MVP - VB\)"
wrote:
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word,
Now.
The formula below is an example of the code.


Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today
End Sub


Although I am not sure why VBA cares about it, the variable name "today" is
where your problem is. I'm guessing it is a reserved keyword for VBA inside
of Excel... change the variable name and your code should work fine (unless
you stumble upon another keyword, that is<g).

Rick


Today is an Excel function.


Mark Lincoln

Now Function Question
 
In my previous post, I missed that you are looking to put the month
into B1. If you set the formatting of B1 to "mmmm", it will display
the month.

On Jun 22, 4:23 pm, Nausett wrote:
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word, Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub




Rick Rothstein \(MVP - VB\)

Now Function Question
 
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the
word,
Now.
The formula below is an example of the code.


Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today
End Sub


Although I am not sure why VBA cares about it, the variable name "today"
is
where your problem is. I'm guessing it is a reserved keyword for VBA
inside
of Excel... change the variable name and your code should work fine
(unless
you stumble upon another keyword, that is<g).

Rick


Today is an Excel function.


I realize that at the spreadsheet level, but Today does not seem to be
"defined" within the VBA world itself.

Rick


Don Guillett

Now Function Question
 
sub don()'will put 6 in cell b1
range("b1")=month(date)
end sub
--
Don Guillett
SalesAid Software

"Nausett" wrote in message
...
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word,
Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub





Mark Lincoln

Now Function Question
 
That's what I was trying to say. One uses Date in VBA, but Today in
an Excel workbook. And people wonder why I often look confused....

Mark Lincoln

On Jun 22, 5:13 pm, "Rick Rothstein \(MVP - VB\)"
wrote:
I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the
word,
Now.
The formula below is an example of the code.


Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today
End Sub


Although I am not sure why VBA cares about it, the variable name "today"
is
where your problem is. I'm guessing it is a reserved keyword for VBA
inside
of Excel... change the variable name and your code should work fine
(unless
you stumble upon another keyword, that is<g).


Rick


Today is an Excel function.


I realize that at the spreadsheet level, but Today does not seem to be
"defined" within the VBA world itself.

Rick- Hide quoted text -

- Show quoted text -




Vijay Chary

Now Function Question
 

Hi Nausett !! :)
Today is an Excel Function similar to Now. Try
using another variable name instead of Today !!


"Nausett" wrote:

I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word, Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub




Don Guillett

Now Function Question
 
sub puttodaysdateincellb1()
range("b1")=date
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Vijay Chary" wrote in message
...

Hi Nausett !! :)
Today is an Excel Function similar to Now. Try
using another variable name instead of Today !!


"Nausett" wrote:

I'm trying to use the Now function in VBA. I continue to get a compile
error: Expected function or variable. The error highlights on the word,
Now.
The formula below is an example of the code.

Sub Dateparttest()
Dim today
today = Month(Now)
Range("b1").Value = today

End Sub






All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com