我正在尝试应用lastrow lastcolumn,但没有做到正确。
我收到错误“提取的范围有丢失或非法的字段名称”
由于
Sub FilterCopyToOtherSheet2()
Dim lastRow As Long
Dim lastCol As Long
Dim colChr As String
With Sheets("Comments-Tableau")
lastCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
lastRow = .Cells(.Rows.Count, lastCol).End(xlUp).Row
End With
Sheets("Comments-Tableau").Range(Cells(2, 2), Cells(lastRow, lastCol)).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheets("Comments").Range("A1"), _
Unique:=False
Application.DisplayAlerts = False
Sheets("Comments-Tableau").Delete
Application.DisplayAlerts = True
End Sub
答案 0 :(得分:1)
我可能错了,但这可能会这样做:
Sheets("Comments-Tableau").UsedRange.offset(1,1).Copy
Sheets("Comments").Activate
Sheets("Comments").Range("A1").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False ' exit copy mode
签出Missing or Illegal Field Name您需要在复制操作中包含标题。
Sheets("Sheet1").Range(Cells(1, 1), Cells(lastRow, lastCol)).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheets("Sheet2").Range("A1"), _
Unique:=False