Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Convert Date to End of Month

If cell "a1" has a date, how could I check whether the date is the end of the
month and if not change it to the end of the month?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Convert Date to End of Month

=EOMONTH(A1,0)
Format as any type of date you want.

HTH,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Stratuser" wrote:

If cell "a1" has a date, how could I check whether the date is the end of the
month and if not change it to the end of the month?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Convert Date to End of Month

Here is another way which doesn't require the Analysis ToolPak...

=IF(DAY(A1+1)1,DATE(YEAR(A1),MONTH(A1)+1,0),A1)

--
Rick (MVP - Excel)


"Stratuser" wrote in message
...
If cell "a1" has a date, how could I check whether the date is the end of
the
month and if not change it to the end of the month?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Convert Date to End of Month

I got hung up on your "how do you test" question that I didn't pay attention
to what you ultimately wanted. This simpler formula will yield the end of
the month date for the date specified in A1...

=DATE(YEAR(A8),MONTH(A8)+1,0)

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Here is another way which doesn't require the Analysis ToolPak...

=IF(DAY(A1+1)1,DATE(YEAR(A1),MONTH(A1)+1,0),A1)

--
Rick (MVP - Excel)


"Stratuser" wrote in message
...
If cell "a1" has a date, how could I check whether the date is the end of
the
month and if not change it to the end of the month?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Convert Date to End of Month

Is this a VB question by any chance? And if so, did you want to physically
change the date in A1 from whatever it is to the end of its month (thus
losing whatever was in the cell to begin with)? If the answer to both of
these questions are "Yes", then try this macro out...

Sub ChangeDateToEndOfMonth()
With Range("A1")
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
End With
End Sub

--
Rick (MVP - Excel)


"Stratuser" wrote in message
...
If cell "a1" has a date, how could I check whether the date is the end of
the
month and if not change it to the end of the month?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Convert Date to End of Month

I have a very old Excel program that imports data with dates, but I have
recently started working in Excel 2007. I'm trying to check each of the
dates in VBA to make sure that each one is the end of the month. For some
reason, the Eomonth command is not working in the old worksheet, although the
same code works fine when I've tested it by entering the data by hand in a
test worksheet. This has me thinking that the problem may be the data
itself, not the code.

Basically, the code is like this:

For each cell in Selection

Next cel

"Rick Rothstein" wrote:

Is this a VB question by any chance? And if so, did you want to physically
change the date in A1 from whatever it is to the end of its month (thus
losing whatever was in the cell to begin with)? If the answer to both of
these questions are "Yes", then try this macro out...

Sub ChangeDateToEndOfMonth()
With Range("A1")
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
End With
End Sub

--
Rick (MVP - Excel)


"Stratuser" wrote in message
...
If cell "a1" has a date, how could I check whether the date is the end of
the
month and if not change it to the end of the month?




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Convert Date to End of Month

It's a VBA question. I'm trying to make sure all the dates in a selected
range of imported data are the end of their respective months. The code I
have works fine in a test worksheet when I enter the data manually, but not
in an old worksheet. This makes me wonder whether I have a data problem.
Maybe Eomonth is not evaluating the dates in the old worksheet correctly.

It should be as simple as this:

For each cel in Selection
cel.value = Eomonth(cel.value, 0)
Next cel

But when my code sees 4/30/2006 in the old worksheet, Eomonth returns 31.


"Rick Rothstein" wrote:

Is this a VB question by any chance? And if so, did you want to physically
change the date in A1 from whatever it is to the end of its month (thus
losing whatever was in the cell to begin with)? If the answer to both of
these questions are "Yes", then try this macro out...

Sub ChangeDateToEndOfMonth()
With Range("A1")
.Value = DateSerial(Year(.Value), Month(.Value) + 1, 0)
End With
End Sub

--
Rick (MVP - Excel)


"Stratuser" wrote in message
...
If cell "a1" has a date, how could I check whether the date is the end of
the
month and if not change it to the end of the month?




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Convert Date to End of Month

It should be as simple as this:

For each cel in Selection
cel.value = Eomonth(cel.value, 0)
Next cel


Try it this way...

For Each Cel In Selection
Cel.Value = DateSerial(Year(Cel.Value), Month(Cel.Value) + 1, 0)
Next

--
Rick (MVP - Excel)
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Convert Date to End of Month

That worked. Thanks very much.

"Rick Rothstein" wrote:

It should be as simple as this:

For each cel in Selection
cel.value = Eomonth(cel.value, 0)
Next cel


Try it this way...

For Each Cel In Selection
Cel.Value = DateSerial(Year(Cel.Value), Month(Cel.Value) + 1, 0)
Next

--
Rick (MVP - Excel)

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
Convert Date in Text to month and Year Excellency Excel Worksheet Functions 3 March 24th 10 02:42 AM
convert date to text month april Excel Discussion (Misc queries) 2 March 3rd 10 06:18 PM
Convert Month, Week, Year to date Pete Hay Excel Worksheet Functions 3 February 2nd 10 12:43 AM
convert date to name of month holly Excel Discussion (Misc queries) 6 July 30th 09 01:13 AM
Convert date to number representing Month Karin Excel Discussion (Misc queries) 5 November 14th 08 06:09 AM


All times are GMT +1. The time now is 08:54 PM.

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"