Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default 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 -



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default 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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function Question Having Issues Excel Worksheet Functions 5 May 18th 09 10:17 PM
Function Question SteveDB1 Excel Worksheet Functions 8 March 16th 09 02:23 PM
Function Question steinerdf Excel Worksheet Functions 3 February 18th 09 10:54 PM
IF Function question. Excel beginner Excel Worksheet Functions 6 August 9th 07 04:13 PM
Function Question Andrew Excel Worksheet Functions 2 May 25th 05 07:58 AM


All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"