Excel VBA AND <>

CIRonin

New Member
Joined
Apr 19, 2019
Messages
2
Hey all
I have some code that hides rows if a value in a column is = "TERMDT" which works great... But I am trying to get some working that has a few criteria
What they asked for is "IF column Z (new status) is W, hide/remove UNLESS column D (BDCA code) is MMJ, MBJ, MNN, MBN, MML, MMP
"
The first bit is
<code>
Sub HideRows1()
BeginRow = 1
EndRow = 1000
ChkCol = ("BX")


For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = "TERMDT" Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
End If
Next RowCnt
End Sub
</code>

The second bit that I can't get to work yet is...
<code>
Sub HideRows2()
BeginRow = 1
EndRow = 1000
ChkCol = ("Z")
ChkColB = ("D")


For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = "W" Then
Cells(RowCnt, ChkColB).Value <>"MMJ" AND
Cells(RowCnt, ChkColB).Value <>"MBJ" AND
Cells(RowCnt, ChkColB).Value <> "MNN" AND
Cells(RowCnt, ChkColB).Value <> "MBN" AND
Cells(RowCnt, ChkColB).Value <> "MML" AND
Cells(RowCnt, ChkColB).Value <> "MMP" AND
Then


Cells(RowCnt, ChkCol).EntireRow.Hidden = True
End If
Next RowCnt
End Sub
</code>
Any suggestions for a VBA novice?
Thanks!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & welcome to MrExcel.
How about
Code:
Sub CIRonin()
   Dim Cl As Range
   Dim Ary As Variant
   
   Ary = Array("MMJ", "MBJ", "MNN", "MBN", "MML", "MMP")
   For Each Cl In Range("Z2", Range("Z" & Rows.Count).End(xlUp))
      If Cl = "W" Then
         If IsError(Application.Match(Cl.Offset(, -22), Ary, 0)) Then Cl.EntireRow.Hidden = True
      End If
   Next Cl
End Sub
 
Upvote 0
That worked like a charm!
Thanks!

Hi & welcome to MrExcel.
How about
Code:
Sub CIRonin()
   Dim Cl As Range
   Dim Ary As Variant
   
   Ary = Array("MMJ", "MBJ", "MNN", "MBN", "MML", "MMP")
   For Each Cl In Range("Z2", Range("Z" & Rows.Count).End(xlUp))
      If Cl = "W" Then
         If IsError(Application.Match(Cl.Offset(, -22), Ary, 0)) Then Cl.EntireRow.Hidden = True
      End If
   Next Cl
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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