Do While loop resets?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • if1467
    New Member
    • Feb 2008
    • 25

    Do While loop resets?

    I am using VB6.3 out of excel and I have the following section of code:

    Code:
    Dim rownum As Integer
    Dim colnum As Integer
    Dim currcell As Range
    Dim UnmatchedCount As Integer
    Dim CTDate As String
    
    If UnmatchedCount > 0 Then
        rownum = Blockrow1
        Set currcell = ActiveSheet.Cells(rownum, colnum)
        colnum = colnum + 1
        CTDate = ActiveSheet.Cells(rownum, colnum).Value
        colnum = colnum - 1
        
        Do While currcell <> ""
        
            If currcell.Interior.ColorIndex = 33 Then
                currcell.Select
                Selection.Delete Shift:=xlUp
                colnum = colnum - 1
                Set currcell = ActiveSheet.Cells(rownum, colnum)
                currcell.Select
                Selection.Delete Shift:=xlUp
                colnum = colnum + 2
                Set currcell = ActiveSheet.Cells(rownum, colnum)
                currcell.Select
                Selection.Delete Shift:=xlUp
                colnum = colnum - 1
            Else
                colnum = colnum + 1
                Set currcell = ActiveSheet.Cells(rownum, colnum)
                currcell = CTDate
                colnum = colnum - 1
                rownum = rownum + 1
            End If
            Set currcell = ActiveSheet.Cells(rownum, colnum)
        Loop
    End If
    (The variables are set previously in the macro and I have showed the Dims just for reference)

    The problem is that when it loops to the top for some reason it is not using the new currcell that it is set to at the bottom. It is using the same currcell that it started with? What am I missing?

    Thanks for any input.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Is it possible you should be leaving out the Set keyword? As in...
    [CODE=vb]currcell = ActiveSheet.Cel ls(rownum, colnum)[/CODE]Note - not telling you, just asking.

    Comment

    • if1467
      New Member
      • Feb 2008
      • 25

      #3
      Originally posted by Killer42
      Is it possible you should be leaving out the Set keyword? As in...
      [CODE=vb]currcell = ActiveSheet.Cel ls(rownum, colnum)[/CODE]Note - not telling you, just asking.
      I tried that and the error "object required" came up. Any other ides?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by if1467
        I tried that and the error "object required" came up. Any other ides?
        Have you traced through the execution to make sure it's doing exactly what you think? And have you checked that colnum and rownum have the expected values each time around the loop?

        Comment

        Working...