VBA multiple "not equal to statements"

RosieRose

Board Regular
Joined
Jul 29, 2014
Messages
75
I have written code so that if the cell content if is equal content is equal to a set variable, then the macros counts it as a value of one (this works great), I need to add code, so that if the cell content is not blank, or not equal to the previous variables it will also count as one , I am having trouble with the "not equal to" statement
Code:
     If Cells(DateIndex - k, j + 1) = "0" And Cells(5, j + 1).Value = "HIGH" Then
                Condition1 = Condition1 1
            
                ElseIf Cells(DateIndex - k, j + 1) = "Z" Then
                   Condition2= Condition2 + 1
                ElseIf Cells(DateIndex - k, j + 1) = "Y" Then
                    Condition3 = Condition3 + 1
                ElseIf Cells(DateIndex - k, j + 1) = "X" Then
                    Condition4 = Condition4 + 1
                ElseIf Cells(DateIndex - k, j + 1) = "W" Then
                    Condition5 = Condition5 + 1
                ElseIf Cells(DateIndex - k, j + 1) = "V" Then
                    Condition6 = Condition6 + 1
ElseIf Cells(DateIndex - k, j + 1) <> "Z" And "Y" And "X" And "W" And "V" And "0" Then
                    OtherRead= OtherRead + 1
it is this last line of code that is not working for me
Code:
ElseIf Cells(DateIndex - k, j + 1) <> "A" And "B" And "C" And "D" And "E" And "0" Then
    OtherRead= OtherRead + 1
I am getting error code 13 mismatch. any help is much appreciated.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Try changing that line to this:
Code:
ElseIf Cells(DateIndex - k, j + 1) <> "A" And Cells(DateIndex - k, j + 1) <> "B" And Cells(DateIndex - k, j + 1) <>"C" And Cells(DateIndex - k, j + 1) <>"D" And Cells(DateIndex - k, j + 1) <> "E" And Cells(DateIndex - k, j + 1) <> "0" Then
 
Upvote 0

RosieRose

Board Regular
Joined
Jul 29, 2014
Messages
75
Thank you JoMo, I am no longer getting the error message, but I am still not getting the code to count for me (which I suspect is a problem elsewhere, I will need to comb through and find). However, I realized that I will also need to exclude blank cells. do I need to add:
Code:
And Cells(DateIndex - k, j + 1) <>""
Thank you
 
Upvote 0

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
That addition will exclude blanks if that's necessary.
 
Upvote 0

Forum statistics

Threads
1,191,204
Messages
5,985,275
Members
439,953
Latest member
suchitha

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