OR operator [VBA]

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hello,

I used this code (see below) to delete the entire row if the cell in the column contains the value "GL".

Code itself works well.

Would it be possible to add the OR operator to this code so I can add more values than just "GL"?

I want to add 2 more values.

Thank you very much!

VBA Code:
Sub MA_GL()

Dim Rng As Range
Set Rng = ActiveSheet.UsedRange

For i = Rng.Cells.count To 1 Step -1
If Rng.Item(i).Value = "GL" Then
Rng.Item(i).EntireRow.DELETE
End If
Next i

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
hi

would it not just be

VBA Code:
If Rng.Item(i).Value = "GL" or Rng.Item(i).Value = "newvalue1" or Rng.Item(i).Value = "newvalue2" Then

dave
 
Upvote 0
Solution
Thank you for your help SQUIDD.

Works perfectly. (y)
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,289
Members
449,149
Latest member
mwdbActuary

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