使用宏,如何根据列“N”值脚本删除2列(T& U)?

时间:2014-09-22 19:48:30

标签: excel vba excel-vba

我需要帮助使用VBA编程宏来删除“T& U”列中基于等于“已关闭”的列“N”的所有值。

所以为了简化这一点:如果列“N”=已关闭,则列“T”和“U”应该没有值。

谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个:

Sub Clearer()
    Dim i As Long
    Dim w As Worksheet
    Dim r As Range
    Dim r1 As Long

    Set w = Sheet1 'Set this to the (name) of the sheet.
    Set r = w.UsedRange

    r1 = r.Row

    For i = r1 To r1 + r.Rows.Count - 1
        If w.Cells(i, 14) = "Closed" Then w.Range(w.Cells(i, 20), w.Cells(i,  21)).ClearContents
    Next i

    MsgBox "Done!"

End Sub