Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Date Format Changes on Copy

Has anyone come across this one...?

Whilst copying from a .csv file into an existing Excel workbook a
strange things happens...

The first column of my range loses its date format and changes from a
UK (the one I want) to a US format, peculiarly only on some cells!
Setting the format on the destination cells first first makes no
difference. I'm doing the copy in VBA using:

wkbSource.Sheets(1).UsedRange.Copy _
wkbTarget.Sheets("Timesheet Actuals").Range("A2")

Even more peculiarly, if I carry out the copy by hand the problem
doesn't occur...!

TIA

Jon C

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date Format Changes on Copy

VBA works in US English. So if the date can be interpreted as US, it is.
This is not true for Excel itself.

However, I doubt the problem is with the code you show, but in the code that
opens the CSV file. If you have xl2002 or later, you can
use the arguments for Data=Import External Data to help control this I
believe.

--
Regards,
Tom Ogilvy


"Jon C" wrote in message
oups.com...
Has anyone come across this one...?

Whilst copying from a .csv file into an existing Excel workbook a
strange things happens...

The first column of my range loses its date format and changes from a
UK (the one I want) to a US format, peculiarly only on some cells!
Setting the format on the destination cells first first makes no
difference. I'm doing the copy in VBA using:

wkbSource.Sheets(1).UsedRange.Copy _
wkbTarget.Sheets("Timesheet Actuals").Range("A2")

Even more peculiarly, if I carry out the copy by hand the problem
doesn't occur...!

TIA

Jon C



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Date Format Changes on Copy

Thanks Tom.

I'm using xl2002. The code's pretty straight forward:

Set wkbTarget = ActiveWorkbook

'
' Select file to load
'

fName = Application.GetOpenFilename("Replicon Files (*.csv), *.csv")

If fName < False Then
Set wkbSource = Workbooks.Open(fName)
wkbSource.Activate

Rows("1:3").Select
Selection.Delete Shift:=xlUp

wkbSource.Sheets(1).UsedRange.Copy _
wkbTarget.Sheets("Timesheet Actuals").Range("A2")

wkbSource.Close SaveChanges:=False

End If

......

Is there an argument I can add to the Workbook Open?

I looked up the 'Import' method in xl help and it said if should be
used! I guess I'm not looking in the right place.

Jon C

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Date Format Changes on Copy

Sorry, xl Help said Import should NOT be used...

Jon C

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date Format Changes on Copy

Try setting the Local argument to the workbook.open method to True.

Sorry, xl Help said Import should NOT be used...

Should not be used for what? Importing?

--
Regards,
Tom Ogilvy


"Jon C" wrote in message
oups.com...
Sorry, xl Help said Import should NOT be used...

Jon C





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
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
Changing date format in copy paste Wullie Excel Discussion (Misc queries) 2 December 8th 08 01:06 PM
Copy/Paste Special (Date Format) Saxman Excel Discussion (Misc queries) 0 September 27th 06 02:43 PM
How do I maintain my date format, when I copy a sheet, in excel? DHT Excel Discussion (Misc queries) 2 June 29th 05 03:31 AM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 10:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"