NearlyThere
New Member
- Joined
- Feb 18, 2022
- Messages
- 2
- Office Version
- 2016
Hello, need help please with a Macro copying data from a "Source" to "Target" worksheet using the column heading (In this example "ITEM"). It currently includes hidden cells (filtered in "Source"). Id like to exclude these cells from coping to Target. Struggling to incorporate SpecialCells(xlCellTypeVisible).
Dim ws As Worksheet
Dim aCell As Range, Rng As Range
Dim col As Long, lRow As Long
Dim colName As String
'~~> Change this to the relevant sheet
Set ws = ActiveWorkbook.Sheets("Source")
'ITEM Copy
With ws
Set aCell = .Range("A1:E1").Find(What:="ITEM", LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False)
'~~> If Found
If Not aCell Is Nothing Then
col = aCell.Column
colName_ITEM_Name = Split(.Cells(, col).Address, "$")(1)
'MsgBox "colname_ITEM_Name " & colName_ITEM_Name
lRow = .Range(colName_ITEM_Name & .Rows.Count).End(xlUp).Row
MsgBox "Columns Copied = " & lRow
'~~> This is your range
Set Rng = .Range(colName_ITEM_Name & "2:" & colName_ITEM_Name & lRow)
Debug.Print Rng.Address
'~~> If not found
Else
MsgBox "ITEM Count Not Found"
End If
End With
Sheets("Target").Range(colName_ITEM_Name & ":" & colName_ITEM_Name & lr).Copy Sheets("Target").Range("A" & Rows.Count).End(xlUp).Offset(0)
Range("A1").Select
Dim ws As Worksheet
Dim aCell As Range, Rng As Range
Dim col As Long, lRow As Long
Dim colName As String
'~~> Change this to the relevant sheet
Set ws = ActiveWorkbook.Sheets("Source")
'ITEM Copy
With ws
Set aCell = .Range("A1:E1").Find(What:="ITEM", LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False)
'~~> If Found
If Not aCell Is Nothing Then
col = aCell.Column
colName_ITEM_Name = Split(.Cells(, col).Address, "$")(1)
'MsgBox "colname_ITEM_Name " & colName_ITEM_Name
lRow = .Range(colName_ITEM_Name & .Rows.Count).End(xlUp).Row
MsgBox "Columns Copied = " & lRow
'~~> This is your range
Set Rng = .Range(colName_ITEM_Name & "2:" & colName_ITEM_Name & lRow)
Debug.Print Rng.Address
'~~> If not found
Else
MsgBox "ITEM Count Not Found"
End If
End With
Sheets("Target").Range(colName_ITEM_Name & ":" & colName_ITEM_Name & lr).Copy Sheets("Target").Range("A" & Rows.Count).End(xlUp).Offset(0)
Range("A1").Select