Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 - |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Function Question | Excel Worksheet Functions | |||
Function Question | Excel Worksheet Functions | |||
Function Question | Excel Worksheet Functions | |||
IF Function question. | Excel Worksheet Functions | |||
Function Question | Excel Worksheet Functions |