Thread
:
Problem with the "Or" operand in Excel
View Single Post
#
2
Posted to microsoft.public.excel.programming
Don Guillett[_2_]
external usenet poster
Posts: 1,522
Problem with the "Or" operand in Excel
You were saying < which is NOT equal instead of = Also, work from the
bottom up
Sub MyHideRowsSAS()
Rows.Hidden = False
For i = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1
If LCase(Cells(i, 3)) = "fred" Or _
LCase(Cells(i, 3)) = "john" Or _
LCase(Cells(i, 3)) = "mary" Then Rows(i).Hidden = True
Next i
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"PPL" wrote in message
...
Excel 2002/3
I am trying to write a short script that looks at all cells in column C
and if the cell contains a selected name (i.e., Fred or John or Mary) then
the entire row is hidden
I would have thought that the following would have doen it?
Sub MyHideRows()
Dim startrow As Integer
startrow = 1
Do Until startrow Cells(Cells.Rows.Count, "C").End(xlUp).Row
If Cells(startrow, 3).Value < "Fred" _
Or Cells(startrow, 3).Value < "John" _
Or Cells(startrow, 3).Value < "Mary" Then
Cells(startrow, 3).Select
Selection.EntireRow.Hidden = True
End If
startrow = startrow + 1
Loop
End Sub
The result is that regardless of content the script hides all rows
Interstingly if I strip out the "Or" operands and leave the basic "If"
statement it works fine.
So this works:
If Cells(startrow, 3).Value < "Fred" Then
Cells(startrow, 3).Select
Selection.EntireRow.Hidden = True
End If
Can somebody please please help me with the logic here (or my lack of
same!)
TIA
Phil
Reply With Quote
Don Guillett[_2_]
View Public Profile
Find all posts by Don Guillett[_2_]