WildBurrow
New Member
- Joined
- Apr 5, 2021
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
I've found code that will copy/paste select columns from a row of data that has been filtered. The code works fine if I paste to a "dummy" sheet that does not contain any merged cells.
However, my target sheet has several merged cells below the area where the pasted data is to be placed. I receive an error message that it cannot paste into merged cells (because it's looking at the entire column).
The copy range will always be limited to 12 rows and my target sheet provides 12 rows for the pasted data. Below are images of my sheets.
Source Sheet: Target Sheet:
This is the code that I have thus far:
Code source from: VBA Copy and Paste Certain Columns of a sheet to specific columns on another sheet
How do I identify the target sheet range in order to avoid the merge error?
Vikki
However, my target sheet has several merged cells below the area where the pasted data is to be placed. I receive an error message that it cannot paste into merged cells (because it's looking at the entire column).
The copy range will always be limited to 12 rows and my target sheet provides 12 rows for the pasted data. Below are images of my sheets.
Source Sheet: Target Sheet:
This is the code that I have thus far:
VBA Code:
Sub CopyTabletoCOC() 'This works only if all the rows within the column are not merged
Dim ws2 As Worksheet, ws3 As Worksheet, lRow As Long
'Set Sheet reference
Set ws2 = worksheets("Tables")
Set ws3 = worksheets("Fake")
lRow = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).row
With ws2
.range("AX1").AutoFilter Field:=1, Criteria1:="Y" 'set your filter
'copy the visible cells in each column from row 2 and resize to the last row
'paste to the the cell you want your copied range to start in your second worksheet
.range("AY2").Resize(lRow).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.range("B2") 'Collection Number
.range("AZ2").Resize(lRow).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.range("G2") 'Date
.range("BA2").Resize(lRow).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.range("J2") 'Time
.range("BB2").Resize(lRow).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.range("AD2") 'Latitude
.range("BC2").Resize(lRow).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.range("AH2") 'Longitude
.range("AX1").AutoFilter 'clear the filter
End With
End Sub
Code source from: VBA Copy and Paste Certain Columns of a sheet to specific columns on another sheet
How do I identify the target sheet range in order to avoid the merge error?
Vikki