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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

A Durfani

Active Member
Joined
Apr 12, 2019
Messages
256
Office Version
  1. 2013
Platform
  1. Windows
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
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,023
Office Version
  1. 365
Platform
  1. Windows
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
 

A Durfani

Active Member
Joined
Apr 12, 2019
Messages
256
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

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
 

A Durfani

Active Member
Joined
Apr 12, 2019
Messages
256
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,023
Office Version
  1. 365
Platform
  1. Windows
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.
 

A Durfani

Active Member
Joined
Apr 12, 2019
Messages
256
Office Version
  1. 2013
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,160
Messages
5,640,481
Members
417,146
Latest member
MacAlexandreL

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
Top