What code to change to delete rows?

bdunk

Active Member
Joined
Aug 1, 2002
Messages
290
I am using the following code to delete rows that have a "0" or nothing in the Column A cell value.

Sub Test1()
With Columns(1)
.Replace What:="0", Replacement:="", LookAt:=xlWhole
.SpecialCells(4).EntireRow.Delete
End With
End Sub

How would I modify this code to look in column C for cells that have a "1"? If it does then delete the whole row.

Thanks for the help.

PS what does the .SpecialCells(4).EntireRow.Delete line of code do?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
SpecialCells(4) is telling the code to delete the entire row for each cell that is blank within column A.

It can also be referenced as SpecialCells(xlCellTypeBlanks).

Assuming there are no blanks in column C that you want to keep, you could simply use the same code with a minor change.

Code:
Sub Test1()
With Columns(3) '3 =column C
.Replace What:="1", Replacement:="", LookAt:=xlWhole
.SpecialCells(4).EntireRow.Delete
End With
End Sub
 
Upvote 0
Thanks

Thanks Kristy works great. I just wasn't patient enough for it to complete its job.

Bdunk
 
Upvote 0
One more question

How would I add looking for value "0" also in this code. So I want it to look for 1 or 0 in Column C. I have it working for 1 or nothing I just want it to look for "0" as well.

Thanks

Brian
 
Upvote 0
Hi!

Try adding this line before the .specialcells(4)...statement:
Code:
.Replace What:="0", Replacement:="", LookAt:=xlWhole

This way it should replace all 1's with blanks, then all of the 0's. Then it deletes the blank cells. :)
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top