Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Get Last Day of Month

Below I have code that finds a date in a cell like "200412". The line that
sets "sDateRange" returns "12/1/2004" which is correct. My problem is the
last line that sets sLastDayMonth variable.

For some reason, sLastDayMonth returns "1/12/1900" but I want it to return
"12/31/2004".
What am I doing wrong?

Dim sDateRange As Date, sLastDayMonth As Date, cell As Range

Set cell = FindCell("To Period", Sheets(1).Cells).Offset(0, 2)
sDateRange = CDate(Right(cell.Value, 2) & "/" & (Left(cell.Value,
Len(cell) - 2)))
sLastDayMonth = CDATE(YEAR(sDateRange),MONTH(sDateRange)+1,0)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Get Last Day of Month

CDate takes a single string as it's argument. You want the DateSerial
function. It uses the 3 parts you specified...

HTH

"scott" wrote:

Below I have code that finds a date in a cell like "200412". The line that
sets "sDateRange" returns "12/1/2004" which is correct. My problem is the
last line that sets sLastDayMonth variable.

For some reason, sLastDayMonth returns "1/12/1900" but I want it to return
"12/31/2004".
What am I doing wrong?

Dim sDateRange As Date, sLastDayMonth As Date, cell As Range

Set cell = FindCell("To Period", Sheets(1).Cells).Offset(0, 2)
sDateRange = CDate(Right(cell.Value, 2) & "/" & (Left(cell.Value,
Len(cell) - 2)))
sLastDayMonth = CDATE(YEAR(sDateRange),MONTH(sDateRange)+1,0)



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
excel to make the days cary over month to month automaticly GARY New Users to Excel 1 April 19th 08 06:05 PM
Excel 2003 month to month data change grid Chad[_2_] Excel Discussion (Misc queries) 2 February 15th 08 01:36 AM
Create Month Timetable on a worksheet different month each works Courtney Excel Worksheet Functions 1 October 15th 06 11:48 AM
When using MONTH function on Blank Cell!! Returns Month=Jan! mahou Excel Discussion (Misc queries) 6 January 9th 06 02:46 AM
transfer cell $ amount to other sheet month-to-month without overc Colin2u Excel Discussion (Misc queries) 1 July 28th 05 02:36 AM


All times are GMT +1. The time now is 09:06 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"