Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default Identify last date of a specific month

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Identify last date of a specific month

Hi Papa,

Does this from the Jan 2004 archive do what you want?

Dan

Newsgroups: microsoft.public.excel.programming
From: "Bob Phillips"
Date: Thu, 22 Jan 2004 09:43:21 -0000
Local: Thurs, Jan 22 2004 1:43 am
Subject: Calculating Last day of month

Jon,

Along the same lines as Rob, but a little shorter

myDate = DateSerial(Year(Date), Month(Date) + 1, 0)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Rob van Gelder" wrote in
message
...

Jon,


A cool behaviour of DateSerial is that it accepts values outside the

bounds
of a calendar month/day. This means you can choose month 13, which is
interpreted as month 12 + 1


dtmTemp = Now()
dtmTemp = DateSerial(Year(dtmTemp), Month(dtmTemp) + 1, 1) - 1


Rob


"Jon" wrote in message
...
I am having a problem with calculating the last day of the current month

in excel. If I use the EOMONTH function with parameters NOW() and 0 i.e.
EOMONTH(NOW(), 0) in the cell where I want the date to go everything works
fine. However
I want to put the EOMONTH into a macro at which point the compiler

complain the EOMONTH is not a defined sub or function. Are there any VB
functions that will return the last day of the current month


thank you in advanced


Jon

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Identify last date of a specific month

In VBA or via formula, I think your easiest option will be to find the first
date of the subsequent month, and subtract 1.

Formula Example:
Cell A1 = Dec 2008
Cell B1 =
DATE(ROUND(((YEAR(A1)*12+MONTH(A1)+1)/12),0),MOD((YEAR(A1)*12+MONTH(A1)+1),12),1)-1

Code example:
Sub LastMonthDay()
OrgDate = Sheet1.Range("A1").Value
NextMonthStartDate = DateSerial(Year(OrgDate), Month(OrgDate), 1)

ActualLastDay = NextMonthStartDate - 1
End Sub


HTH,
Keith

"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Identify last date of a specific month

Oops, on that VBA it should be
Month(OrgDate) + 1
(I forgot the +1 in the first reply)

"ker_01" wrote:

In VBA or via formula, I think your easiest option will be to find the first
date of the subsequent month, and subtract 1.

Formula Example:
Cell A1 = Dec 2008
Cell B1 =
DATE(ROUND(((YEAR(A1)*12+MONTH(A1)+1)/12),0),MOD((YEAR(A1)*12+MONTH(A1)+1),12),1)-1

Code example:
Sub LastMonthDay()
OrgDate = Sheet1.Range("A1").Value
NextMonthStartDate = DateSerial(Year(OrgDate), Month(OrgDate), 1)

ActualLastDay = NextMonthStartDate - 1
End Sub


HTH,
Keith

"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default Identify last date of a specific month

Keith,
I tried the worksheet function and have interesting results. For the dates
in Dec 08, it worked well in that it identified 12/31/08 as the last date of
December.
However, for all the other dates, it added a year. For example June 09
dates resulted in 6/30/10.
Maybe I buggered your formula. My dates are in column H and this is how I
substituted to accomodate.
=DATE(ROUND(((YEAR(H3)*12+MONTH(H3)+1)/12),0),MOD((YEAR(H3)*12+MONTH(H3)+1),12),1)-1


"ker_01" wrote:

In VBA or via formula, I think your easiest option will be to find the first
date of the subsequent month, and subtract 1.

Formula Example:
Cell A1 = Dec 2008
Cell B1 =
DATE(ROUND(((YEAR(A1)*12+MONTH(A1)+1)/12),0),MOD((YEAR(A1)*12+MONTH(A1)+1),12),1)-1

Code example:
Sub LastMonthDay()
OrgDate = Sheet1.Range("A1").Value
NextMonthStartDate = DateSerial(Year(OrgDate), Month(OrgDate), 1)

ActualLastDay = NextMonthStartDate - 1
End Sub


HTH,
Keith

"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Identify last date of a specific month

Hi Papa,

Assuming that B1 is the header the following is the worksheet function for
last day of month. Look up EOMONTH in help for more info.

=EOMONTH(B1,0)

Using the function on the worksheet, it works irrespective of whether B1 is
formatted as text or as a date formatted as mmmm-yy.

If used in VBA as

WorksheetFunction.EoMonth(Range("B1"), 0)

then it works if B1 is a date formatted as mmmm-yy but if B1 is text, it
cannot evaluate a 2 digit year and 08 becomes the current year. However, it
can evaluate December 2008.

--
Regards,

OssieMac


"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default Identify last date of a specific month

OssieMac,
I am apparently not getting it. My headers are in row 2. My dates are in
column H.
I have tried =eomonth(h2,0) and I have tried =eomonth(h3,0)
Both have resulted in #Name?
I have tried formatting the cell as a date. I'm not sure what is happening.
There doesn't seem to be any help for the EOMonth function either.

"OssieMac" wrote:

Hi Papa,

Assuming that B1 is the header the following is the worksheet function for
last day of month. Look up EOMONTH in help for more info.

=EOMONTH(B1,0)

Using the function on the worksheet, it works irrespective of whether B1 is
formatted as text or as a date formatted as mmmm-yy.

If used in VBA as

WorksheetFunction.EoMonth(Range("B1"), 0)

then it works if B1 is a date formatted as mmmm-yy but if B1 is text, it
cannot evaluate a 2 digit year and 08 becomes the current year. However, it
can evaluate December 2008.

--
Regards,

OssieMac


"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Identify last date of a specific month

You are getting a #Name? error, not a #VALUE! error? Give this a try
anyway...

The EOMONTH function is part of the Analysis ToolPak add-in... you need to
click Tools/Add-Ins, put a check mark next to Analysis ToolPak and then
click OK. Now, press F9 to force sheet to be recalculated and I think your
errors will go away.

--
Rick (MVP - Excel)


"Papa Jonah" wrote in message
...
OssieMac,
I am apparently not getting it. My headers are in row 2. My dates are in
column H.
I have tried =eomonth(h2,0) and I have tried =eomonth(h3,0)
Both have resulted in #Name?
I have tried formatting the cell as a date. I'm not sure what is
happening.
There doesn't seem to be any help for the EOMonth function either.

"OssieMac" wrote:

Hi Papa,

Assuming that B1 is the header the following is the worksheet function
for
last day of month. Look up EOMONTH in help for more info.

=EOMONTH(B1,0)

Using the function on the worksheet, it works irrespective of whether B1
is
formatted as text or as a date formatted as mmmm-yy.

If used in VBA as

WorksheetFunction.EoMonth(Range("B1"), 0)

then it works if B1 is a date formatted as mmmm-yy but if B1 is text, it
cannot evaluate a 2 digit year and 08 becomes the current year. However,
it
can evaluate December 2008.

--
Regards,

OssieMac


"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format
is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in
that
month. I need to do this in order to calculate the number of days
between
that date and today.
TIA,
Papa


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Identify last date of a specific month

Hi Papa,

Did Rick's suggestion work? It should. I forgot about the function being
part of the Analysis Tool Pak.

If it still doesn't work, what version of Excel are you using? Help back as
far as XL2002 has info on EOMONTH function. I don't suppose you were looking
in Help under the VBA editor. If you have help open with VBA and change to
worksheet then you have to click help again because they are 2 completely
different helps.


--
Regards,

OssieMac


"Papa Jonah" wrote:

OssieMac,
I am apparently not getting it. My headers are in row 2. My dates are in
column H.
I have tried =eomonth(h2,0) and I have tried =eomonth(h3,0)
Both have resulted in #Name?
I have tried formatting the cell as a date. I'm not sure what is happening.
There doesn't seem to be any help for the EOMonth function either.

"OssieMac" wrote:

Hi Papa,

Assuming that B1 is the header the following is the worksheet function for
last day of month. Look up EOMONTH in help for more info.

=EOMONTH(B1,0)

Using the function on the worksheet, it works irrespective of whether B1 is
formatted as text or as a date formatted as mmmm-yy.

If used in VBA as

WorksheetFunction.EoMonth(Range("B1"), 0)

then it works if B1 is a date formatted as mmmm-yy but if B1 is text, it
cannot evaluate a 2 digit year and 08 becomes the current year. However, it
can evaluate December 2008.

--
Regards,

OssieMac


"Papa Jonah" wrote:

I have a spreadsheet that identifies months in a column. The format is:
December-08 (for December 2008).
I need to take that and identify that 12/31/2008 is the last date in that
month. I need to do this in order to calculate the number of days between
that date and today.
TIA,
Papa

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
if todays date is in the month of january, then specific drop down list, if feb, another list, etc bjohnson Excel Programming 1 September 19th 07 01:15 PM
In Excel How do I return the Month for a specific date Ashok Natarajan Excel Discussion (Misc queries) 1 January 23rd 06 09:05 AM
Returning the Week Number of a Specific Date on a Month arjcvg Excel Worksheet Functions 0 November 5th 04 01:21 AM
Returning the Week Number of a Specific Date on a Month arjcvg Excel Worksheet Functions 1 November 3rd 04 04:35 AM
Returning the Week Number of a Specific Date on a Month arjcvg Excel Worksheet Functions 0 November 3rd 04 04:26 AM


All times are GMT +1. The time now is 04:58 PM.

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"