我需要將數據從一個表格複製到另一個表格並粘貼到列標題匹配的下一個可用行中。 我無法創建要複製的範圍。將過濾的範圍複製到第二行,其中列標題匹配
這似乎是這個問題 - rng1.SpecialCells(xlCellTypeVisible).Copy目的地:=表( 「資金的總和」)範圍(tCell.Offset(1)& lRow)
我ahve嘗試創建要粘貼到使用單元格和範圍的目標,但我似乎無法正確地將語法添加到語法。 我在做什麼錯?
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
'如果不aCell是Nothing Then' - 哪裏是'aCell'而來? –
對不起我的壞 - 我後來改變了變量名稱。我已經修改了上面的代碼。但這不是問題。 – user3432849
@ user3432849,請考慮關於[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) –