Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Manipulating date

I'm wondering if there is a way with VBA to correc dates that look like this
(all of them are MAY dates). Is not a format issue as they look typed like
that:
10/5/2009
1/05/2009
04/5/2009
1/5/09
5/10/09
05/10/2009
5/1/09
5/01/09
etc

--
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Manipulating date

If you can have both 10/5/2009 and 05/10/2009 on the same sheet (column?),
then no, a macro will not be able to figure out (on its own) that May was
meant for both. You could write a macro that would ask you for the month and
have the code use that information to straighten things out, but this would
require you to select **all** the May dates manually before running the
macro. Would that be an acceptable solution? Also, are these values
formatted as Text or do they show as real Excel Dates in the cells?

--
Rick (MVP - Excel)


"Alfredo_CPA" .(donotspam) wrote in message
...
I'm wondering if there is a way with VBA to correc dates that look like
this
(all of them are MAY dates). Is not a format issue as they look typed like
that:
10/5/2009
1/05/2009
04/5/2009
1/5/09
5/10/09
05/10/2009
5/1/09
5/01/09
etc

--
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Manipulating date

I know for sure the month is May as I receive a monthly file with just one
month data, but for some reason I Ireceive it with the dates in all the ways
I decribed in my original posting i.e. next month I will have the same
problem with Jun data (06/01/09, 02/06/09, 3/06/09, etc - all will be June
dates)
Thanks


"Rick Rothstein" wrote:

If you can have both 10/5/2009 and 05/10/2009 on the same sheet (column?),
then no, a macro will not be able to figure out (on its own) that May was
meant for both. You could write a macro that would ask you for the month and
have the code use that information to straighten things out, but this would
require you to select **all** the May dates manually before running the
macro. Would that be an acceptable solution? Also, are these values
formatted as Text or do they show as real Excel Dates in the cells?

--
Rick (MVP - Excel)


"Alfredo_CPA" .(donotspam) wrote in message
...
I'm wondering if there is a way with VBA to correc dates that look like
this
(all of them are MAY dates). Is not a format issue as they look typed like
that:
10/5/2009
1/05/2009
04/5/2009
1/5/09
5/10/09
05/10/2009
5/1/09
5/01/09
etc

--
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Manipulating date

try this UDF
in the spreadsheet you'd enter
=CorrectedDate(B6,5) where B6 is a date like your 5/10/2009 and 5 is the
correct month --- means you can use this for june, july etc
the answer will be an excel date, so format the cell appropriately like
"dd-mmm-yy" or whatever

Option Explicit
Function CorrectedDate(text As String, mnth As Long) As Date
' input v1/v2/yyyy
' where either v1 or v2 is correct month
Dim dte As Variant ' becomes a vector with 3 values
dte = Split(text, "/") ' dte becomes a vector with 3 values

If dte(0) = mnth Then
' text is mm/dd/yy
CorrectedDate = DateSerial(dte(2), dte(0), dte(1))
Else
' text is dd/mm/yy
CorrectedDate = DateSerial(dte(2), dte(1), dte(0))
End If
End Function




"Alfredo_CPA" .(donotspam) wrote in message
...
I'm wondering if there is a way with VBA to correc dates that look like
this
(all of them are MAY dates). Is not a format issue as they look typed like
that:
10/5/2009
1/05/2009
04/5/2009
1/5/09
5/10/09
05/10/2009
5/1/09
5/01/09
etc

--
Thanks


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
Manipulating date Jacob Skaria Excel Programming 0 June 11th 09 04:16 PM
Manipulating Date Using Dropdown Les Linton Excel Discussion (Misc queries) 0 January 10th 08 02:34 AM
Manipulating dates Peter Excel Discussion (Misc queries) 5 October 26th 07 05:36 PM
Manipulating dates (was Add 6 months to a date) Bill Ridgeway New Users to Excel 2 March 31st 06 07:46 PM
Manipulating DOS from VBA Dave Peterson[_3_] Excel Programming 0 October 17th 03 01:46 AM


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