我想要复制筛选表中剩余的单元格,但只复制它们的值,而不是公式。我使用了下面的方法,除非过滤器只为Sheets("Cost Accounting").Range(A2).PasteSpecial xlPasteValues代码行留下一行错误"script out of range“,否则效果很好。
我附上了一个示例的图像,其中的代码不会粘贴(当过滤器之后只剩下一行时) Example Problem Scenario
有什么想法吗?
子DT_test()
Dim table As ListObject
Dim rngToCopy As Range
Sheets.Add.Name = ("Cost Accounting")
Sheets("Cost Accounting").Activate
TeamRole2 = "Cost Accounting"
MaxDate = Date
Set table = Worksheets("Overview").ListObjects("Table1")
table.Range.AutoFilter Field:=13, Criteria1:=TeamRole2
table.Range.AutoFilter Field:=8, Criteria1:="<" & MaxDate
On Error Resume Next
Set rngToCopy = table.DataBodyRange.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rngToCopy Is Nothing Then
rngToCopy.Copy
Sheets("Cost Accounting").Range(A2).PasteSpecial xlPasteValues
End If
table.Range.AutoFilter结束子对象
发布于 2020-08-13 04:08:31
尝试粘贴这些值...
If Not rngToCopy Is Nothing Then
rngToCopy.Copy
Sheets("Cost Accounting").Range("A2").PasteSpecial xlPasteValues
End Ifhttps://stackoverflow.com/questions/63383821
复制相似问题