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感謝您的反饋。 –