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

Excel has misinterpretted the date values from a web query - so Feb-08
is 01/02/08 rather than 08/02/07. The problem is that if I use VBA to
correct this it uses the underlying excel date value (ie 39479) rather
than the cell contents.

I want to do something like this - but on the cell contents:

Public Sub fixdates()
Application.ScreenUpdating = False
For Each Cell In ActiveSheet.UsedRange.Columns("h:h").Cells
Cell.Value = DateValue(Right(Cell.Value, 2) & "/02/07")
Next Cell
Application.ScreenUpdating = True
End Sub

Any suggestions?

Thanks in advance,

Kieran

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default reformating date

Hi Kieran:

Try this:

cell.Value = DateSerial(2007, 2, Right(cell.Text, 2))

You may also want to automate the fixdates a little with checking for the
year and the month.

as in month is month(datevalue("1/" & left(cell.text,3) & "/2006"))
and that can fit in the above in place of the 2 after 2007.
For year just use year(now()).


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


" wrote:

Excel has misinterpretted the date values from a web query - so Feb-08
is 01/02/08 rather than 08/02/07. The problem is that if I use VBA to
correct this it uses the underlying excel date value (ie 39479) rather
than the cell contents.

I want to do something like this - but on the cell contents:

Public Sub fixdates()
Application.ScreenUpdating = False
For Each Cell In ActiveSheet.UsedRange.Columns("h:h").Cells
Cell.Value = DateValue(Right(Cell.Value, 2) & "/02/07")
Next Cell
Application.ScreenUpdating = True
End Sub

Any suggestions?

Thanks in advance,

Kieran


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
Date Reformating Question Ksean Excel Discussion (Misc queries) 2 December 9th 09 09:16 PM
Pivot tables reformating Pascale Excel Discussion (Misc queries) 0 January 23rd 08 02:25 AM
Reformating a column and getting it to apply Thansal New Users to Excel 2 July 7th 06 03:04 PM
How can I defeat Excel's auto-reformating into date format? stebro Excel Discussion (Misc queries) 2 December 2nd 04 03:39 PM
reformating worksheet Warren Excel Programming 1 September 16th 03 09:14 AM


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