我在试着让这个代码工作
For Each dest In destSS
Hoja8.ListObjects("BD").range.AutoFilter Field:=9, Criteria1:= _
Array(dest), Operator:=xlFilterValues
Hoja8.ListObjects("BD").range.AutoFilter Field:=10, Criteria1:= _
"<=.8", Operator:=xlFilterValues
With Hoja8.ListObjects("BD").Sort
.SortFields.Clear
.SortFields.Add Key:=range("BD[Load Status]"), Order:=xlDescending
.SortFields.Add Key:=range("BD[Destination]"), Order:=xlAscending
.SortFields.Add Key:=range("BD[Current Location]"), Order:=xlAscending
.SortFields.Add Key:=range("BD[Event]"), Order:=xlAscending
.SortFields.Add Key:=range("BD[Dwell]"), Order:=xlDescending
.Apply
End With
On Error Resume Next
Set myRange = Hoja8.ListObjects("BD").DataBodyRange.CurrentRegion.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If myRange Is Nothing Then
'Do nothing
Else
'do stuff
Sheets("BD").Activate
range("A1").Select
With Hoja8.ListObjects("BD")
Union(.ListColumns(9).range, _
.ListColumns(1).range, _
.ListColumns(3).range, _
.ListColumns(5).range, _
.ListColumns(8).range, _
.ListColumns(10).range, _
.ListColumns(15).range, _
.ListColumns(17).range, _
.ListColumns(19).range).Select
Selection.Copy
Sheets("Recently Placed").Select
'check ifs there any data in the sheet and if there are, find the last row to paste the data--------------
If WorksheetFunction.CountA(range("C1").CurrentRegion) = 0 Then
range("C1").Select
ActiveSheet.Paste
Else
lscol = range("C" & rows.count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
End If
End With
Set myRange = Nothing
End If
Next
columns("G").Cut
columns("C").Insert
Call SortDB
Application.ScreenUpdating = True
End Sub
它运行正常,但当过滤后的数据显示什么也没有时,它仍然在复制头部,当我输入-1时,它根本不复制任何数据,你能帮我吗?
我尝试了这段代码,并运行,但当过滤器显示什么行仍然复制标题
2条答案
按热度按时间9lowa7mx1#
在循环中“重置”对象变量
myRange
,也就是说,在属于If myRange Is Nothing
的End If
之前,使用Set myRange = Nothing
行。0pizxfdo2#
请尝试以下代码...