Find exact match within a column and select

trw88

New Member
Joined
Apr 5, 2021
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
I have a sheet with part numbers in column A and qty's in column B (this is the only data on the sheet). I want code to find the 0 qty's in column B and delete those rows. It has to be an exact match so that rows that contain 30, 10, etc. would not get deleted. Thanks in advance!

1617731456925.png
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try

VBA Code:
Sub DelZeroColB()
'delete values where zero in value in column B

Dim lastrow As Long, r As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row

For r = lastrow To 2 Step -1
If Cells(r, "B") = 0 Then
Rows(r).EntireRow.Delete
End If
Next r

End Sub
 
Upvote 0
Solution
If Cells(r, "B") = o Then
That looks like a lower case "o" (the letter "o").
It should be the number 0.

Also, you do not need "EntireRow" when using row.
You can just use:
VBA Code:
Rows(r).Delete
 
Upvote 0
That looks like a lower case "o" (the letter "o").
It should be the number 0.

Also, you do not need "EntireRow" when using row.
You can just use:
VBA Code:
Rows(r).Delete
Thank you Joe
Changed it
 
Upvote 0
That looks like a lower case "o" (the letter "o").
It should be the number 0.

Also, you do not need "EntireRow" when using row.
You can just use:
VBA Code:
Rows(r).Delete

Will it make any difference?

EntireRow and
Rows(r).Delete
 
Upvote 0
Will it make any difference?

EntireRow and
Rows(r).Delete
Rows(r).EntireRow.Delete
and
Rows(r).Delete
will do the exact same thing.

If you are referencing the row already using "Rows", you do not need to use "EntireRow", it is completely unnecessary (it is redundant, as the row is already implied).

You typically use "EntireRow" when you are using a single cell references, i.e.
Range("A10).EntireRow.Delete
or
Cell.EntireRow.Delete
which is telling it whatever row that single cell is in, delete the whole row.
 
Upvote 0
Rows(r).EntireRow.Delete
and
Rows(r).Delete
will do the exact same thing.

If you are referencing the row already using "Rows", you do not need to use "EntireRow", it is completely unnecessary (it is redundant, as the row is already implied).

You typically use "EntireRow" when you are using a single cell references, i.e.
Range("A10).EntireRow.Delete
or
Cell.EntireRow.Delete
which is telling it whatever row that single cell is in, delete the whole row.
Thank you very much Joe for explaining
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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