Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Jean Mark
 
Posts: n/a
Default Date problem using VBA

I have written a small macro to format raw data from an accounting system to
a useable format in excel. The accounting system stores dates as dd.mm.yyyy.
As Excel wont recognise this as a date, the code I have written to convert
the date columns is simply:
Columns("E:E").Replace What:=".", Replacement:="/"
Columns("E:E").NumberFormat = "dd/mm/yyyy;@"
However, any date that wouldn't make sense in an american format
(mm/dd/yyyy) stays stored as text until you click in the actual cell. All my
settings are up as English UK, why is this happening? I have even tried
adding tricks into the VBA code that work to convert these date fields
manually, but don't in the VBA code! An example is typing "1" into an empty
cell, then copying, and paste special multiply across all the date range.
Works manually, but not in VBA!
The line where the error starts is the 'replacement' line. If I do this
manually excel immediately recognises the entire column as dates. If I do
this with VBA code it doesn't. Any ideas?
Thanks.
--
JM
  #2   Report Post  
HiArt
 
Posts: n/a
Default


Hi

Columns("E:E").NumberFormat = "dd/mm/yyyy;@"


not sure you need the ;@ at the end of the NumberFormat argument. You
could try that.

Otherwise this code works fine for me. Have you turned off automatic
updates, secrren refreshes or something?

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=390125

  #3   Report Post  
Jean Mark
 
Posts: n/a
Default

HiArt,

Thanks for your response. The problem I am certain lies in some setting
where VBA is thinking dates in US format, and the spreadsheet settings are in
UK format, but I can't for the life of me figure it out. My logic for
thinking this is that, after running the macro, if I go into the spreadsheet
, turn on the macro recorder, and double click on one of these cells that
aren't recognised as date (e.g. cell E7 containing "30/06/2005") and hit
return (so now it magically does recognise as a date) and then read the code
the macro recorder has written, it shows:
ActiveCell.FormulaR1C1 = "6/30/2004"
Range("E8").Select
Anyway, I have found the following slightly unsatisfactory temporary fix. I
have adjusted the code as follows:
Columns("E:E").Replace What:=".", Replacement:="/"
Range("E7").Select
Do Until ActiveCell.Value = ""
ActiveCell.FormulaR1C1 = DateValue(ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
Columns("E:E").NumberFormat = "dd/mm/yyyy"

Works for now. Let me know if you have any other brainwaves.

JM

--
JM


"HiArt" wrote:


Hi

Columns("E:E").NumberFormat = "dd/mm/yyyy;@"


not sure you need the ;@ at the end of the NumberFormat argument. You
could try that.

Otherwise this code works fine for me. Have you turned off automatic
updates, secrren refreshes or something?

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=390125


  #4   Report Post  
Koen_VN
 
Posts: n/a
Default


Hi,

I'm not quite sure, but try to verify your settings (start - control
panel - regional and language options). Check what's in 'short date',
maybe by changing this, your problem will be solved.

Koen


--
Koen_VN
------------------------------------------------------------------------
Koen_VN's Profile: http://www.excelforum.com/member.php...o&userid=25593
View this thread: http://www.excelforum.com/showthread...hreadid=390125

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
Time Date Formula Problem Oowf Excel Worksheet Functions 2 June 1st 05 06:01 PM
Login Logout Date Problem ascool_asice Excel Worksheet Functions 2 May 30th 05 12:50 AM
Identifying Date Overlaps Tremain Excel Discussion (Misc queries) 1 May 10th 05 01:58 AM
Date and Time Picker Control problem Andy Tallent Excel Discussion (Misc queries) 0 May 4th 05 12:50 PM
dsum with date criteria Jed Martin Excel Worksheet Functions 0 March 24th 05 05:29 PM


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