![]() |
Excel 2007 for next loop bug
The below routine now works just fine, but if I replace the first line with
two lines as follows , the For I1 = 7 to vbr Step 3 loop below starts out with I1 set to the value of vbr every time. It took a while to find the work around, but now it works fine. I'm wondering if there are other for-next issues lurking out there that I need to be aware of. Anyway, if I replace the first executable line in the routine below with the following two lines, it consistently fails as described above. Replacing those two lines with the equivalent one line, makes it work normally with I1 being set to 7 the first time thru the loop. sname = ActiveSheet.Name LastChar = right(sname,2) Sub HideUnHideClosedLegs() LastChar = Right(ActiveSheet.Name, 2) If IsNumeric(LastChar) Then HideFlag = Cells(2, 1).Value If HideFlag = "H" Then R1 = "7:60000" Rows(R1).Select Selection.EntireRow.Hidden = False HideFlag = "" Cells(2, 1).Value = HideFlag Exit Sub Else HideFlag = "H" Cells(2, 1).Value = HideFlag End If Call ReturnBottomRow(vBottomRow) vbr1 = vBottomRow + 0 For i1 = 7 To vbr1 Step 3 i = i1 OpenFlag = Cells(i, 1).Value If OpenFlag = 0 Then j = i + 2 R1 = i & ":" & j Rows(R1).Select Selection.EntireRow.Hidden = True End If Next i1 Else msg = "blah blah blah." mtitle = "blah blah blah." x = MsgBox(msg, vbOKOnly, mtitle) End If End Sub |
All times are GMT +1. The time now is 10:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com