1
我需要通过删除特定位置的行来清理一些记录,这些位置与我们没有交往。我想知道如何编写VBA代码来搜索目的地城市和目的地国家列(在我当前的情况下列L & M)并删除匹配特定城市和州的记录。如何根据VBA中的2列中的条件删除行?
我已经想出了如何通过同一列内的多个条件删除记录,但不是跨列删除记录。
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With Sheets("data_export")
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For lRow = Lastrow To Firstrow Step -1
With .Cells(lRow, "D") 'Stops'
If Not IsError(.Value) Then
If .Value >= "1" Then .EntireRow.Delete
End If
End With
With .Cells(lRow, "P") 'HaZMat
If Not IsError(.Value) Then
If .Value <> "" Then .EntireRow.Delete
End If
End With
With .Cells(lRow, "T") 'Service
If Not IsError(.Value) Then
If .Value <> "Truck Load" Then .EntireRow.Delete
End If
End With
Next lRow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
是的,这正是我所需要的。非常感谢! – BarryMahnly
@BryryMahnly感谢您的反馈。 –