Excel 2007 for next loop bug

U

Ullrich Fischer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top