Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Help with error

I'm a relative newby with VBA. I need to return the last day of the month
for a series of dates. I have found this formula many places on the web, but
get a compile error with it.

dtEOM =DATE(YEAR(A1),MONTH(A1)+1,0)

where dtEOM is my vairable declared as a Date. The error is a
'Compile Error: Expected: )'
and YEAR is highlighted.

My intent is to fill dtEOM with the month, create some record counts, and go
to the next month, reset the variable, and do it again. Your help is
appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Help with error

Not YEAR(A1)
but
YEAR(Range("A1").Value)
--
Gary's Student
gsnu200703


"Wiley" wrote:

I'm a relative newby with VBA. I need to return the last day of the month
for a series of dates. I have found this formula many places on the web, but
get a compile error with it.

dtEOM =DATE(YEAR(A1),MONTH(A1)+1,0)

where dtEOM is my vairable declared as a Date. The error is a
'Compile Error: Expected: )'
and YEAR is highlighted.

My intent is to fill dtEOM with the month, create some record counts, and go
to the next month, reset the variable, and do it again. Your help is
appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Help with error

Thanks, but I still get the error. Here is the edited line I am using now:

dtEOM = DATE(YEAR(Range("D2").Value),MONTH(Range("D2").Val ue)+1,0)

Ultimately, I want to return the date on a vairable which is the first day
fo the month, so I beleive I want ti to look like this:

dtEOM = DATE(YEAR(dtBOM),MONTH(dtBOM)+1,0)

But that gives me the same error. As a test I have set dtBOM prioor to this
line as:
dtBOM = "06/01/2006"

NOTE: I would use the EOM function in Excel, but as a guest on this PC, I
cannot install the Analysis Toolpak.

"Gary''s Student" wrote:

Not YEAR(A1)
but
YEAR(Range("A1").Value)
--
Gary's Student
gsnu200703


"Wiley" wrote:

I'm a relative newby with VBA. I need to return the last day of the month
for a series of dates. I have found this formula many places on the web, but
get a compile error with it.

dtEOM =DATE(YEAR(A1),MONTH(A1)+1,0)

where dtEOM is my vairable declared as a Date. The error is a
'Compile Error: Expected: )'
and YEAR is highlighted.

My intent is to fill dtEOM with the month, create some record counts, and go
to the next month, reset the variable, and do it again. Your help is
appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with error

try:

dtEOM = dateserial(year(.....

=date() is a worksheet function.


Wiley wrote:

Thanks, but I still get the error. Here is the edited line I am using now:

dtEOM = DATE(YEAR(Range("D2").Value),MONTH(Range("D2").Val ue)+1,0)

Ultimately, I want to return the date on a vairable which is the first day
fo the month, so I beleive I want ti to look like this:

dtEOM = DATE(YEAR(dtBOM),MONTH(dtBOM)+1,0)

But that gives me the same error. As a test I have set dtBOM prioor to this
line as:
dtBOM = "06/01/2006"

NOTE: I would use the EOM function in Excel, but as a guest on this PC, I
cannot install the Analysis Toolpak.

"Gary''s Student" wrote:

Not YEAR(A1)
but
YEAR(Range("A1").Value)
--
Gary's Student
gsnu200703


"Wiley" wrote:

I'm a relative newby with VBA. I need to return the last day of the month
for a series of dates. I have found this formula many places on the web, but
get a compile error with it.

dtEOM =DATE(YEAR(A1),MONTH(A1)+1,0)

where dtEOM is my vairable declared as a Date. The error is a
'Compile Error: Expected: )'
and YEAR is highlighted.

My intent is to fill dtEOM with the month, create some record counts, and go
to the next month, reset the variable, and do it again. Your help is
appreciated.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Help with error

Thanks Dave. You headed me in the right direction. Now I know the
difference between a worksheet function and a VBA function. You get the
kudos for that. I'll work with dateserial to see what I can come up with.

"Dave Peterson" wrote:

try:

dtEOM = dateserial(year(.....

=date() is a worksheet function.


Wiley wrote:

Thanks, but I still get the error. Here is the edited line I am using now:

dtEOM = DATE(YEAR(Range("D2").Value),MONTH(Range("D2").Val ue)+1,0)

Ultimately, I want to return the date on a vairable which is the first day
fo the month, so I beleive I want ti to look like this:

dtEOM = DATE(YEAR(dtBOM),MONTH(dtBOM)+1,0)

But that gives me the same error. As a test I have set dtBOM prioor to this
line as:
dtBOM = "06/01/2006"

NOTE: I would use the EOM function in Excel, but as a guest on this PC, I
cannot install the Analysis Toolpak.

"Gary''s Student" wrote:

Not YEAR(A1)
but
YEAR(Range("A1").Value)
--
Gary's Student
gsnu200703


"Wiley" wrote:

I'm a relative newby with VBA. I need to return the last day of the month
for a series of dates. I have found this formula many places on the web, but
get a compile error with it.

dtEOM =DATE(YEAR(A1),MONTH(A1)+1,0)

where dtEOM is my vairable declared as a Date. The error is a
'Compile Error: Expected: )'
and YEAR is highlighted.

My intent is to fill dtEOM with the month, create some record counts, and go
to the next month, reset the variable, and do it again. Your help is
appreciated.


--

Dave Peterson

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
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Form Err.Raise error not trapped by entry procedure error handler [email protected] Excel Programming 1 February 8th 06 10:19 AM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 03:35 AM.

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

About Us

"It's about Microsoft Excel"