PDA

View Full Version : Solved: Help using For loop in a IF then statement



nepotist
04-22-2009, 12:13 PM
hello guys ,

I am designing a custom ribbon for my application and here is my code Sub FacilityType_Change(control As IRibbonControl, text As String)

Dim Rw As Integer
Dim F As Integer

Worksheets("Report").Activate

Rw = ActiveSheet.Cells(Rows.Count, "d").end(xlUp).Rows

If text = "All Facilities" Then
Cells.Select
Range("E1").Activate
Selection.EntireRow.Hidden = False
If text = "SIS Facilities" Then
Cells.Select
Range("E1").Activate
Selection.EntireRow.Hidden = False
F = 1
For Rw = Rw To 3 Step -1
If Cells(Rw, 3).Value <> F Then
Cells(Rw, 3).EntireRow.Hidden = True
Next Rw
ElseIf text = "Arterial Facilities" Then
Cells.Select
Range("E1").Activate
Selection.EntireRow.Hidden = False
F = 3
For Rw = Rw To 3 Step -1
If Cells(Rw, 3).Value <> F Then
Cells(Rw, 3).EntireRow.Hidden = True
Next Rw
End If


End Sub

when I run it , I get an error Next with out For ,,
Guess I cannot use a for loop statement in a if then statement
any help or clue or any other way for me to to do it ??

Thank you

Bob Phillips
04-22-2009, 12:19 PM
Sub FacilityType_Change(control As IRibbonControl, text As String)

Dim Rw As Integer
Dim F As Integer

Worksheets("Report").Activate

Rw = ActiveSheet.Cells(Rows.Count, "d").End(xlUp).Rows

If text = "All Facilities" Then
Cells.Select
Range("E1").Activate
Selection.EntireRow.Hidden = False
If text = "SIS Facilities" Then
Cells.Select
Range("E1").Activate
Selection.EntireRow.Hidden = False
F = 1
For Rw = Rw To 3 Step -1
If Cells(Rw, 3).Value <> F Then
Cells(Rw, 3).EntireRow.Hidden = True
Next Rw
ElseIf text = "Arterial Facilities" Then
Cells.Select
Range("E1").Activate
Selection.EntireRow.Hidden = False
F = 3
For Rw = Rw To 3 Step -1
If Cells(Rw, 3).Value <> F Then
Cells(Rw, 3).EntireRow.Hidden = True
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
' Missing an End If here
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Next Rw
End If


End Sub

nepotist
04-22-2009, 12:21 PM
hey xld .. thanks for pointing it out but it still gives me the same error , the error is popping up at the first next rw statement

nepotist
04-22-2009, 12:23 PM
My bad I was missing one more end if :D thankx XLD