Loop statement doesn't work right 
Author Message
 Loop statement doesn't work right

I have this loop statement in a macro and it is just not working right.
totalCell2 keeps the same value when it hits the next TOTAL: Here is my code
below. Any ideas?

Sub NewTotalLineTest()
   With Worksheets("glffile").Range("F1:F999")
   Set r = .Find("REFND MAN")
   If Not r Is Nothing Then
        firstAddress = r.Address
            rrow = r.Row
            Set r = .FindNext(r)
        Loop While Not r Is Nothing And r.Address <> firstAddress
    End If
    End With
End Sub

'Sub TrueTotalLine()
   'Dim totalCell2 As Range

'End Sub

Sub NewTotalLine()

    With Worksheets("glffile").Range("F1:F999")
    Set t = .Find("TOTAL:")
    If Not t Is Nothing Then
        'firstaddress2 = t.Address
            trow = t.Row

            trow = trow + 1
            Range("F" & trow).Select
            Set totalCell2 = ActiveCell

            Columns("F:F").Find(What:="REFND MAN").Activate
            rrow = rrow + 1
            Range("F" & rrow).Select

            With Selection
                .Value = "NEW TOTAL LINE"
                .Font.Bold = True
                .Font.Color = RGB(0, 0, 255)
                .Offset(0, 1).Value = totalCell2.Offset(0, 1).Value
                .Offset(0, 1).Font.Bold = True
                .Offset(0, 1).Font.Color = RGB(0, 0, 255)
                .Offset(0, 3).Value = "<- Enter a new total here if
                .Offset(0, 3).Font.Italic = True
            End With
    End If
    End With

End Sub

Sub NameTotalsLine()
    Dim totalCell As Range

    Selection.Find(What:="NEW TOTAL LINE", after:=ActiveCell,
LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    Set totalCell = ActiveCell
    totalCell.Offset(0, 1).Activate
    ActiveWorkbook.Names.Add Name:="TotalLine", RefersTo:=ActiveCell
End Sub

Wed, 18 Feb 2004 00:07:16 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Nested loop - Why doesn't this work?

2. Comand object in a loop doesn't work

3. right alignment in richtextbox doesn't work

4. Form menu editor doesn't work right??

5. Help: Control Box doesn't work right.

6. Q: Why auto-redraw doesn't work right in Windows-NT

7. AddNew method doesn't work right!!

8. Right$ doesn't work!

9. Update VBA-statement doesn't work

10. SQL Statement doesn't work - please Help!

11. Calling DLL that has a Dir(\\share) statement doesn't work

12. Stupid SQL statement doesn't work


Powered by phpBB® Forum Software