符合标准时的删除线

时间:2016-02-11 13:29:38

标签: excel-vba vba excel

我有一个我正在尝试编写的代码,当E列中的值等于“Holiday”然后删除与“Holiday”行相关联的A和B列时,它会拾取。我有下面的代码,但它在每一行都很引人注目,而不仅仅是带假期的那一行。任何帮助表示赞赏!

Sub Sorting()
Dim ws As Worksheet
Dim rng As Range
Set ws = Worksheets("FedEx Air Ops Workbench Report")
lastrow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row
Debug.Print lastrow
ws.Columns("A:G").Sort key1:=ws.Range("C1"), order1:=xlAscending
ws.Range("G1").FormulaR1C1 = "=VLOOKUP(RC[-2],BUTTONS!R2C9:R6C10,2,FALSE)"
ws.Range("G1").AutoFill Destination:=ws.Range("G1:G" & lastrow), Type:=xlFillDefault
ws.Columns("A:G").Sort key1:=ws.Range("G1"), order1:=xlAscending
ws.Columns("A:F").EntireColumn.AutoFit

For Each rng In ws.Range("E1:E" & lastrow)
If rng.Value = "Holiday" Then
ws.Range("A:B").Font.Strikethrough = True
End If
Next rng
End Sub

1 个答案:

答案 0 :(得分:1)

尝试更改此行:

ws.Range("A:B").Font.Strikethrough = True

要:

ws.Range("A" & rng.Row).Resize(1, 2).Font.Strikethrough = True