Excel vba 6.0 copy date cells date format

Reply

Join Date: Oct 2006
Posts: 7
Reputation: sirving is an unknown quantity at this point 
Solved Threads: 0
sirving sirving is offline Offline
Newbie Poster

Excel vba 6.0 copy date cells date format

 
0
  #1
Oct 7th, 2006
I have written a number of macros which work successfully, but 1 is giving me some trouble. At the start of the macro, I open another excel worksheet and copy data from sheet using [Range("A1", "G30").Copy], then paste using [Range("A2").Select], [ActiveCell.PasteSpecial] on current workbook.

This pastes the data correct except for 1 cell, date and time cell.
This is in format dd/mm/yyyy hh:mm. But when pasted to sheet, the date is converted to American date. mm/dd/yyy hh:mm.

It doesn't mater what the cell format is when pasteSpecial is performed (within macro).

If the same action are done manually, the date is not changed !!!!

Any help would be much appreciated.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Excel vba 6.0 copy date cells date format

 
0
  #2
Oct 7th, 2006
Are you sure there is no macro, formula, or function that is forcing the cell to behave this way in the template? Another solution, is to force the change by using "format" on the cell AFTER the paste operation...
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 7
Reputation: sirving is an unknown quantity at this point 
Solved Threads: 0
sirving sirving is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #3
Oct 8th, 2006
Originally Posted by Comatose View Post
Are you sure there is no macro, formula, or function that is forcing the cell to behave this way in the template? Another solution, is to force the change by using "format" on the cell AFTER the paste operation...

This is extract of code used:

[If FileExists("C:\EM AXH in Period issue.csv") Then
Workbooks.Open Filename:="C:\EM AXH in Period issue.csv"
Cells.Select
Selection.Copy

Windows("template automatic EM last 24hrs iss14.xls").Activate
Sheets("access hub").Select
Range("A1").Select
ActiveCell.PasteSpecial]

Text being copied from EM AXH in PEriod issue.csv and pasted to template automatic EM last 24hrs iss14.xls, sheet access hub.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 7
Reputation: sirving is an unknown quantity at this point 
Solved Threads: 0
sirving sirving is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #4
Oct 8th, 2006
Originally Posted by sirving View Post
This is extract of code used:

[If FileExists("C:\EM AXH in Period issue.csv") Then
Workbooks.Open Filename:="C:\EM AXH in Period issue.csv"
Cells.Select
Selection.Copy

Windows("template automatic EM last 24hrs iss14.xls").Activate
Sheets("access hub").Select
Range("A1").Select
ActiveCell.PasteSpecial]

Text being copied from EM AXH in PEriod issue.csv and pasted to template automatic EM last 24hrs iss14.xls, sheet access hub.
After furtherr investigation, I have found that if i open workbook C:\EM AXH in Period issue.csv manually, the the date format is correct (cell format is set to custom dd/mm/yyyy hh:mm), but if i open the same workbook using [Workbooks.Open Filename:="C:\EM AXH in Period issue.csv"] then the date in the cells is shown as mm/dd/yyyy hh:mm although the format of cell is still set to dd/mm/yyyy. Why is the cells being converted to american date format when the file is opened using a vba macro ???
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1
Reputation: mrdarcy is an unknown quantity at this point 
Solved Threads: 0
mrdarcy mrdarcy is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #5
Oct 28th, 2006
Originally Posted by sirving View Post
After furtherr investigation, I have found that if i open workbook C:\EM AXH in Period issue.csv manually, the the date format is correct (cell format is set to custom dd/mm/yyyy hh:mm), but if i open the same workbook using [Workbooks.Open Filename:="C:\EM AXH in Period issue.csv"] then the date in the cells is shown as mm/dd/yyyy hh:mm although the format of cell is still set to dd/mm/yyyy. Why is the cells being converted to american date format when the file is opened using a vba macro ???
I am having the exact same problem! Did you figure it out, or does anybody know how to get around this problem?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1
Reputation: SirWren is an unknown quantity at this point 
Solved Threads: 0
SirWren SirWren is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #6
Dec 6th, 2006
Originally Posted by mrdarcy View Post
I am having the exact same problem! Did you figure it out, or does anybody know how to get around this problem?
Ok... here's the solution, add the <local:=true> parameter to your VBA macro, e.g.

Workbooks.OpenText Filename:="C:\Test1.csv", DataType:=xlDelimited, _
TextQualifier:=xlTextQualifierNone, FieldInfo:=Array(1, 4), Local:=True
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1
Reputation: MHamlyn is an unknown quantity at this point 
Solved Threads: 0
MHamlyn MHamlyn is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #7
May 10th, 2007
Thankyou so much for this it has helped solve the same problem I have had for a few months.

Now it works perfectly!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 7
Reputation: sirving is an unknown quantity at this point 
Solved Threads: 0
sirving sirving is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #8
May 13th, 2007
Thanks for the info.

The <local:=true> parameter option doesn't appear as an option
for me using Microsoft excel200 vba version 6.

I am still having the same problem
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: Excel vba 6.0 copy date cells date format

 
0
  #9
May 13th, 2007
What dates are being changed ?

Is is dates at beginning of month e.g 7th May or does this happen with dates later in month e.g 17th May also ?

I have had a similar problem in VB5 where some dates change and others don't for which I don't yet have a solution.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 7
Reputation: sirving is an unknown quantity at this point 
Solved Threads: 0
sirving sirving is offline Offline
Newbie Poster

Re: Excel vba 6.0 copy date cells date format

 
0
  #10
May 13th, 2007
First two dates are correct (25/4/07) 2nd 2 dates are incorrect (5/2/07, 5/5/07 & 5/11/07)

Think the 5th is just a coincidence on this example.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC