Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Copy/Paste in VBA fails?

I need to copy down some header text, clear out a spreadsheet, and
then paste the headers back in. I can't get it to work. Anyone see a
problem with...

' copy down the headers we have in the user area
sheet.Range("A3:AZ3").Copy

' clear out anything that used to be in the sheet
sheet.Range("A3:IV5000").ClearContents
sheet.Range("A3:IV5000").ClearComments
sheet.Range("A3:IV5000").Borders.LineStyle = xlNone

' paste the headers back in
sheet.Paste sheet.Range("A3:AZ3")

If the range is empty, the user is presented with an error stating
that the Paste method failed. If it is not empty, they are instead
presented with the "Data on the Clipboard is not the same size and
shape...".

Anyone know how to do this reliably without user intervention?

Maury
  #2   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default Copy/Paste in VBA fails?

Why not leave the header alone and clear out the data below it by changing
the following lines:

sheet.Range("A4:IV5000").ClearContents
sheet.Range("A4:IV5000").ClearComments
sheet.Range("A4:IV5000").Borders.LineStyle = xlNone

--
JT


"Maury Markowitz" wrote:

I need to copy down some header text, clear out a spreadsheet, and
then paste the headers back in. I can't get it to work. Anyone see a
problem with...

' copy down the headers we have in the user area
sheet.Range("A3:AZ3").Copy

' clear out anything that used to be in the sheet
sheet.Range("A3:IV5000").ClearContents
sheet.Range("A3:IV5000").ClearComments
sheet.Range("A3:IV5000").Borders.LineStyle = xlNone

' paste the headers back in
sheet.Paste sheet.Range("A3:AZ3")

If the range is empty, the user is presented with an error stating
that the Paste method failed. If it is not empty, they are instead
presented with the "Data on the Clipboard is not the same size and
shape...".

Anyone know how to do this reliably without user intervention?

Maury

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Copy/Paste in VBA fails?

Or you could do this:

sheet.Range("A3:AZ3").Copy
sheet.Cells.Clear
sheet.Range("A3").PasteSpecial Paste:=xlPasteValues

This assumes nothing in rows 1-2. If rows 1 or 2 contain data that
you want to retain, this suggestion fails.

"Maury Markowitz" wrote:

I need to copy down some header text, clear out a spreadsheet, and
then paste the headers back in. I can't get it to work. Anyone see a
problem with...

' copy down the headers we have in the user area
sheet.Range("A3:AZ3").Copy

' clear out anything that used to be in the sheet
sheet.Range("A3:IV5000").ClearContents
sheet.Range("A3:IV5000").ClearComments
sheet.Range("A3:IV5000").Borders.LineStyle = xlNone

' paste the headers back in
sheet.Paste sheet.Range("A3:AZ3")

If the range is empty, the user is presented with an error stating
that the Paste method failed. If it is not empty, they are instead
presented with the "Data on the Clipboard is not the same size and
shape...".

Anyone know how to do this reliably without user intervention?

Maury

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
Excel VBA Paste of Range with PrefixCharacter fails from VB.NET Nicholas Dreyer Excel Discussion (Misc queries) 0 April 6th 07 04:09 AM
Why Copy/Paste fails using Offset & Resize of myRange? [email protected] Excel Discussion (Misc queries) 3 November 21st 06 02:06 AM
Copy paste code fails Ron Dean[_2_] Excel Programming 0 January 17th 06 11:49 AM
Paste method fails in VBA lalu Excel Programming 4 October 14th 05 03:06 AM
Filter Copy/Paste Fails - Two Ranges Selected? Craigm[_27_] Excel Programming 4 July 15th 05 04:16 PM


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