locked
Deleting contents of cell if less than x RRS feed

  • Question

  • I need a macro that will look in column a and colum b

    if cells values in column a is less than 300 delete the contents,

    if cell values in column B are less than 1 delete the contents

    I have tried recording a macro and doing it manually however as the amount of cells impacted change each time the macro records only what the first range was.

    Any help will be greatly appreciated.

    Tom

    Monday, September 30, 2013 2:31 PM

Answers

  • If you have headers in row 1:

    Sub Macro1()
        With Range("A:A")
            .AutoFilter Field:=1, Criteria1:="<300"
            Intersect(Range("2:" & Rows.Count), .Cells).SpecialCells(xlCellTypeVisible).ClearContents
            .AutoFilter
        End With
        With Range("B:B")
            .AutoFilter Field:=1, Criteria1:="<1"
            Intersect(Range("2:" & Rows.Count), .Cells).SpecialCells(xlCellTypeVisible).ClearContents
            .AutoFilter
        End With
    End Sub

    Monday, September 30, 2013 2:55 PM