Modify VBA Code when Pasting

MikeL

Active Member
Joined
Mar 17, 2002
Messages
492
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have code that copies data from columns A-K of one spreadsheet and pastes into columns A-K of another.

The issue is that I would like to exclude the data in Column I from pasting...ie paste with blanks instead. I would like to modify on the paste side of the code and not in the initial selection if possible.

Code
'Selects col A-K of one spreadsheet
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:K" & LR).SpecialCells(xlCellTypeVisible).Select
Selection.Copy


'Pastes to Consolidation WB...
Can this paste data in col A-K but put override col I with blanks...? Cavaet...There are rows above this pasted data in Col I that shouldn't be deleted. I just want to exclude from the Paste selection

Consolidation.Activate
With Sheets("Sheet1")
.Range("A1").End(xlDown).Offset(1).PasteSpecial Paste:=xlPasteAll
End With


Thanks Mike
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
The cavaet is that this is related to appending data to existing records. I don't want to delete all of Col I. Just the part of the range A-K that I am pasting.

Mike
 
Upvote 0
Code:
Dim LR As Long, Nextrow As Long

LR = Range("A" & Rows.Count).End(xlUp).Row
Nextrow = Consolidation.Sheets("Sheet1").Range("A1").End(xlDown).Offset(1).Row

Range("A2:H" & LR).SpecialCells(xlCellTypeVisible).Copy _
    Destination:=Consolidation.Sheets("Sheet1").Range("A" & Nextrow)
Range("J2:K" & LR).SpecialCells(xlCellTypeVisible).Copy _
    Destination:=Consolidation.Sheets("Sheet1").Range("J" & Nextrow)
 
Upvote 0
Maybe something like this (note the introduction of a new variable)...
Code:
Consolidation.Activate
With Sheets("Sheet1")
  NewDataStartRow = .Range("A1").End(xlDown).Offset(1)
  .Range("A1").End(xlDown).Offset(1).PasteSpecial Paste:=xlPasteAll
  .Range(.Cells(NewDataStartRow, "I"), .Cells(Rows.Count, "I").End(xlUp)).Clear
End With
 
Upvote 0
Rick,
I understand what the code is doing but it errors out on the line

#.Range(.Cells(NewDataStartRow, "I"), .Cells(Rows.Count, "I").End(xlUp)).Clear#


Mike
 
Upvote 0
Rick,
I understand what the code is doing but it errors out on the line

#.Range(.Cells(NewDataStartRow, "I"), .Cells(Rows.Count, "I").End(xlUp)).Clear#
See if this works instead...
Code:
With Sheets("Sheet1")
  NewDataStartRow = .Cells(Rows.Count, "A").End(xlUp).Offset(1).Row
  .Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteAll
  .Range(.Cells(NewDataStartRow, "I"), .Cells(Rows.Count, "I").End(xlUp)).Clear
End With
 
Upvote 0
That worked - Thanks Rick

AlphaFrog - I got your code to work as well

Mike
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,319
Members
452,905
Latest member
deadwings

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top