If does not equal VBA

Godders199

Active Member
Joined
Mar 2, 2017
Messages
305
Office Version
  1. 2013
I have the following code that selects rows where the criteria is met, I want to change this so it looks for rows in column 11 not containing X, y, z for example

If Worksheets("submissions").Cells(i, 11).Value ="Godders" And Worksheets("submissions").Cells(i, 21).Value= "" Then
I know i need to change value = "godders" to <> X

but do i need t create a if command for each, or can i combine X, Y , Z into one statement?

Any help would be appreciated.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,249
Office Version
  1. 365
Platform
  1. Windows
I think this may be what you are looking for:
Code:
[COLOR=#000000][FONT=Calibri]If Worksheets("submissions").Cells(i, 11).Value <>"X" And _
[/FONT][/COLOR][COLOR=#000000][FONT=Calibri]    Worksheets("submissions").Cells(i, 11).Value <>"Y" And _
[/FONT][/COLOR][COLOR=#000000][FONT=Calibri]    Worksheets("submissions").Cells(i, 11).Value <>"Z" And _
[/FONT][/COLOR][COLOR=#000000][FONT=Calibri]    Worksheets("submissions").Cells(i, 21).Value= "" Then[/FONT][/COLOR]
 
Last edited:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,103
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You could reverse the logic:

Code:
Select Case Worksheets("submissions").Cells(i, 11).Value
   Case "X", "Y", "Z"
      ' ignore
   Case Else
     If Worksheets("submissions").Cells(i, 21).Value= "" Then
        ' do something
     End If
End Select
 

Forum statistics

Threads
1,136,338
Messages
5,675,187
Members
419,553
Latest member
hanahass

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