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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,335
Messages
6,124,327
Members
449,155
Latest member
ravioli44

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