vrobinson0304
New Member
- Joined
- Jul 5, 2011
- Messages
- 14
Hello,
I'm trying to write a macro that will delete all rows that don't have certain values in column A. The values are determined in cells O1, O2, and O3. I got the code below to work for values in O1 and O2, however it does not allow me to set a third criteria for O3. I believe I may have to do a an array. Can someone please help! Thank you.
I'm trying to write a macro that will delete all rows that don't have certain values in column A. The values are determined in cells O1, O2, and O3. I got the code below to work for values in O1 and O2, however it does not allow me to set a third criteria for O3. I believe I may have to do a an array. Can someone please help! Thank you.
Code:
[COLOR=#4f6228]Sub DelRows()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/COLOR]
[COLOR=#4f6228] Application.ScreenUpdating = False<o:p></o:p>[/COLOR]
[COLOR=#4f6228] ActiveSheet.AutoFilterMode = False<o:p></o:p>[/COLOR]
[COLOR=#4f6228] On Error Resume Next<o:p></o:p>[/COLOR]
[COLOR=#4f6228] With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)<o:p></o:p>[/COLOR]
[COLOR=#4f6228] .AutoFilter Field:=1, Criteria1:="<>" & Range("O1").Value, Criteria2:="<>" & Range("O2").Value<o:p></o:p>[/COLOR]
[COLOR=#4f6228] .Offset(4).SpecialCells(xlCellTypeVisible).EntireRow.Delete<o:p></o:p>[/COLOR]
[COLOR=#4f6228] .AutoFilter<o:p></o:p>[/COLOR]
[COLOR=#4f6228] End With<o:p></o:p>[/COLOR]
[COLOR=#4f6228] Application.ScreenUpdating = True<o:p></o:p>[/COLOR]
[COLOR=#4f6228]End Sub[/COLOR]