我需要将数据从一个工作表复制到另一个工作表并粘贴到列 Headers 匹配的下一个可用行 . 我无法创建要复制的范围 .
这似乎是问题 - rng1.SpecialCells(xlCellTypeVisible).Copy Destination:= Sheets(“Combined Totals”) . Range(tCell.Offset(1)&lRow)
我已经尝试创建要粘贴到使用单元格和范围的目标,但我似乎无法正确地将变量添加到语法中 . 我究竟做错了什么?
Set this to the relevant worksheet
Set ws = ThisWorkbook.Sheets("OPT 1 Total")
With ws
'~~> Find the cell which has the name
Set sCell = .Range("A1:Z1").Find("MN")
Set tCell = Sheets("Combined Totals").Range("A1:Z1").Find("MN")
'~~> If the cell is found
If Not sCell Is Nothing Then
'~~> Get the last row in that column and check if the last row is > 1
lRow = .Range(Split(.Cells(, sCell.Column).Address, "$")(1) & .Rows.Count).End(xlUp).Row
If lRow > 1 Then
'~~> Set your Range
Set rng1 = .Range(sCell.Offset(1), .Cells(lRow, sCell.Column))
'bCell.Offset(1).Activate
Debug.Print tCell.Address
rng1.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Combined Totals").Range(tCell.Offset(1) & lRow)
'Cells(2, 1).Resize(rng1.Rows.Count) '
'~~> This will give you the address
Debug.Print rng1.Address
End If
End If
End With
1 回答
EDIT2 :参数化....