ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Or Like (https://www.excelbanter.com/excel-programming/338982-like.html)

snax500[_2_]

Or Like
 
In Excel2000, I have the following code:

For Each cll In Range("b8:b380")

' Rows to Hide take out Others if Others is to be shown
If cll Like "Comp $ Program*" Or cll Like "FC Program*" _
Or cll Like "Ship*" _
Or cll Like "Duty*" Or cll Like "Others*" _
Or cll Like "COS*" Or cll Like "LC" _
Or cll Like "Mark*" Or cll Like "Check*" _
Then
cll.Select
Selection.EntireRow.Hidden = True
End If
Next

Actually, I have many more "Or cll Like" lines that I edited out. Is
there another way to code this than using so many multiple Or's?

Thanks


Dave Peterson

Or Like
 
Maybe just build a list and go through them.

Option Explicit
Sub testme()

Dim cll As Range
Dim myList As Variant
Dim iCtr As Long
Dim FoundIt As Boolean

myList = Array("Comp $ Program", _
"FC Program", _
"Ship", _
"Duty", _
"Others", _
"Cos", _
"LC", _
"Mark", _
"Check")

For Each cll In Range("b8:b380").Cells
FoundIt = False
For iCtr = LBound(myList) To UBound(myList)
If LCase(cll.Value) Like LCase(myList(iCtr) & "*") Then
FoundIt = True
Exit For
End If
Next iCtr
Next cll
If FoundIt = True Then
cll.EntireRow.Hidden = True
End If
End Sub

I added the lcase stuff--you may not want it.

snax500 wrote:

In Excel2000, I have the following code:

For Each cll In Range("b8:b380")

' Rows to Hide take out Others if Others is to be shown
If cll Like "Comp $ Program*" Or cll Like "FC Program*" _
Or cll Like "Ship*" _
Or cll Like "Duty*" Or cll Like "Others*" _
Or cll Like "COS*" Or cll Like "LC" _
Or cll Like "Mark*" Or cll Like "Check*" _
Then
cll.Select
Selection.EntireRow.Hidden = True
End If
Next

Actually, I have many more "Or cll Like" lines that I edited out. Is
there another way to code this than using so many multiple Or's?

Thanks


--

Dave Peterson


All times are GMT +1. The time now is 11:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com