If does not equal VBA

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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