問題:刪除當前行VBA
我需要刪除不在我的條件的行。
代碼:
假定所有的值被初始化。
For ind = 2 To lrow
reportProcess = Trim(LTrim(RTrim(ws.Range("G" & ind).Text)))
If reportProcess = "Fulfillment - H/W Direct Customers (Operational)" Or reportProcess = "Revenue - Hardware" Then
brand = "HW"
ElseIf reportProcess = "Revenue - Software" Then
' ~~ Check Control Point Number
subReportProcess = Mid(ws.Range("I" & ind).Text, 12, 3)
If subReportProcess = "201" Or subReportProcess = "202" Or subReportProcess = "203" Or subReportProcess = "204" Or subReportProcess = "205" Then
brand = "PBS"
Else
brand = "SWG"
End If
ElseIf reportProcess = "Revenue - GBS" Or reportProcess = "Revenue - GTS IS" Or reportProcess = "Fulfillment - Services(Operational)" Then
brand = "PBS"
ElseIf reportProcess = "Revenue - TSS" Then
brand = "TSS"
ElseIf reportProcess = "Accounts Receivable" Or reportProcess = "IBM Credit LLC - Accounts Receivable" Then
brand = "AR"
End If
country = Trim(LTrim(RTrim(ws.Range("V" & ind).Text)))
If country = "Taiwan" Then
geo = "Taiwan"
ElseIf country = "India" Then
geo = "India"
ElseIf country = "New Zealand" Or country = "Australia" Then
geo = "ANZ"
ElseIf country = "Hong Kong" Then
geo = "Hong Kong"
ElseIf country = "Philippines" Or country = "Malaysia" Or country = "Singapore" Or country = "Thailand" Or country = "Vietnam" Or country = "Indonesia" Then
geo = "ASEAN"
Else
' ~~ INSERT DELETE ROW HERE
End If
ws.Range("B" & ind) = geo
ws.Range("A" & ind) = brand
Next ind
我的嘗試:
ActiveCell.EntireRow.Delete
- 不過這將刪除所有行
Selection.EntireRow.Delete
- 如上
我如何使用循環來刪除特定的行號相同的結果?
你想刪除哪一行? –
@RachelChia循環中當前的一個,所以如果'ind = 2'且條件不匹配,請將其刪除。 – Hibari
你想刪除整個第二行或第一列第二行?如果你想刪除特定的行例子:ws.Range(「A」&ind)。刪除或整行:行(ind).EntireRow.Delete –