Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default What a Paste

Hi,

What about pasting the string: "MyName" & vbTab & cdbl(cdate("01/12/2004"))
cdbl(cdate(string)) converts the string into a date then into the number
representing the date. (just make sure cdate returns the correct value in the
VB app)
Finally, once you have pasted, if excel displays the number, just apply the
date format on the whole column (or row) of dates, eg:
- assuming you have pasted strings in A1:Z100 and column B contains the dates
- WorkSheet.Range("B1:B100").numberformat = "dd/mm/yyyy"

I hope this will work for you,
Regards,
Sebastien

"Rua" wrote:

Hi all

Just wondering if anyone had encountered this problem before, and if so, had
a better work around than me.

The situation:
I create an Excel 8 application in VB and add a worksheet. All this is fine.
I then build a string in VB which contains numerous datatypes including
Text, numbers, and unfortunately, dates!

A simplified version of this string is "MyName" & vbTab & "01/12/2004" &
vbTab & "0001"
The date here is in the format "dd/mm/yyyy" so reads 1st Dec 2004

In VB I then do the following...

Clipboard.Clear
Clipboard.SetText (string)
WorkSheet.Paste

The problem is, after the paste, the date has been entered in the cell as
"12/01/2004" (American Date Format). To check I'm not insane, I then do a
CTRL-V (Paste), so the same string is on the clipboard, but the date is now
pasted in as "01/12/2004". What's going on behind the scenes???

I've tried formatting the target column with .NumberFormat = "dd/mm/yyyy",
and it doesn't work. My regional settings are also set to "dd/mm/yyyy"

My workaround is to set the target column .NumberFormat to Text (@), but
this means my dates aren't really usable in the Excel sheet

Anyone have any advice - or at least empathy!

  #2   Report Post  
Posted to microsoft.public.excel.programming
Rua Rua is offline
external usenet poster
 
Posts: 1
Default What a Paste

Thanks - that works great. Was thinking about doing something like that but
couldn't find a convert to Serial Date vb function. Would also like to know
what exectly is causing it to behave like that.

Anyway, Thanks! Problem solved!

"sebastienm" wrote:

Hi,

What about pasting the string: "MyName" & vbTab & cdbl(cdate("01/12/2004"))
cdbl(cdate(string)) converts the string into a date then into the number
representing the date. (just make sure cdate returns the correct value in the
VB app)
Finally, once you have pasted, if excel displays the number, just apply the
date format on the whole column (or row) of dates, eg:
- assuming you have pasted strings in A1:Z100 and column B contains the dates
- WorkSheet.Range("B1:B100").numberformat = "dd/mm/yyyy"

I hope this will work for you,
Regards,
Sebastien

"Rua" wrote:

Hi all

Just wondering if anyone had encountered this problem before, and if so, had
a better work around than me.

The situation:
I create an Excel 8 application in VB and add a worksheet. All this is fine.
I then build a string in VB which contains numerous datatypes including
Text, numbers, and unfortunately, dates!

A simplified version of this string is "MyName" & vbTab & "01/12/2004" &
vbTab & "0001"
The date here is in the format "dd/mm/yyyy" so reads 1st Dec 2004

In VB I then do the following...

Clipboard.Clear
Clipboard.SetText (string)
WorkSheet.Paste

The problem is, after the paste, the date has been entered in the cell as
"12/01/2004" (American Date Format). To check I'm not insane, I then do a
CTRL-V (Paste), so the same string is on the clipboard, but the date is now
pasted in as "01/12/2004". What's going on behind the scenes???

I've tried formatting the target column with .NumberFormat = "dd/mm/yyyy",
and it doesn't work. My regional settings are also set to "dd/mm/yyyy"

My workaround is to set the target column .NumberFormat to Text (@), but
this means my dates aren't really usable in the Excel sheet

Anyone have any advice - or at least empathy!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default What a Paste

Sorry, I have no idea what is really going on. The code would behave the same
way as CTRL+V, i would understand, but here, it seems like the Paste in code
doesn't use the local settings as does the CTRL+V. No idea why/how.

Regards,
Seb

"Rua" wrote:

Thanks - that works great. Was thinking about doing something like that but
couldn't find a convert to Serial Date vb function. Would also like to know
what exectly is causing it to behave like that.

Anyway, Thanks! Problem solved!

"sebastienm" wrote:

Hi,

What about pasting the string: "MyName" & vbTab & cdbl(cdate("01/12/2004"))
cdbl(cdate(string)) converts the string into a date then into the number
representing the date. (just make sure cdate returns the correct value in the
VB app)
Finally, once you have pasted, if excel displays the number, just apply the
date format on the whole column (or row) of dates, eg:
- assuming you have pasted strings in A1:Z100 and column B contains the dates
- WorkSheet.Range("B1:B100").numberformat = "dd/mm/yyyy"

I hope this will work for you,
Regards,
Sebastien

"Rua" wrote:

Hi all

Just wondering if anyone had encountered this problem before, and if so, had
a better work around than me.

The situation:
I create an Excel 8 application in VB and add a worksheet. All this is fine.
I then build a string in VB which contains numerous datatypes including
Text, numbers, and unfortunately, dates!

A simplified version of this string is "MyName" & vbTab & "01/12/2004" &
vbTab & "0001"
The date here is in the format "dd/mm/yyyy" so reads 1st Dec 2004

In VB I then do the following...

Clipboard.Clear
Clipboard.SetText (string)
WorkSheet.Paste

The problem is, after the paste, the date has been entered in the cell as
"12/01/2004" (American Date Format). To check I'm not insane, I then do a
CTRL-V (Paste), so the same string is on the clipboard, but the date is now
pasted in as "01/12/2004". What's going on behind the scenes???

I've tried formatting the target column with .NumberFormat = "dd/mm/yyyy",
and it doesn't work. My regional settings are also set to "dd/mm/yyyy"

My workaround is to set the target column .NumberFormat to Text (@), but
this means my dates aren't really usable in the Excel sheet

Anyone have any advice - or at least empathy!

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
Can't Copy and Paste or Paste Special between Excel Workbooks wllee Excel Discussion (Misc queries) 5 April 29th 23 03:43 AM
Paste and Paste Special No Longer Working - Excel 2003 SheriJ Excel Discussion (Misc queries) 2 January 15th 09 09:23 PM
In Excel: add a Paste-Special Option to paste IN REVERSE ORDER. stan-the-man Excel Worksheet Functions 7 June 14th 06 08:10 PM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
Macro to Paste to specific line, and continue to Paste each time on next row not over tomkarakowski[_2_] Excel Programming 1 May 28th 04 06:50 PM


All times are GMT +1. The time now is 06:11 PM.

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"