Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 1004- Loop runs then Errors out - Exel

Status
Not open for further replies.

mac7attack

Technical User
Jan 31, 2004
47
US
Hello,

I have a have big program that I have discussed here before that errors out now. This is about the 10th run-time error I have gotten. Others were easy to fix and now this one perplexes me.

The loop below runs once then returns "Error 1004: Application-defined or Object-defined error" When debugging, the line it highlights is
Analyzed.Cells(GCount, AnWeelCol) = Analyzed.Cells(i, "C")

All variables, except Analyzed, are integers.
Thanks in advanced,
MAC

Code:
For i = DateCellS To DateCellE Step 1
            If (i = 1) Then
                 Analyzed.Cells(GCount, (AnWeekCol + 1)) = 1
            Else
                If Analyzed.Cells(i, "C") <> Analyzed.Cells(i - 1, "C") Then
                    Analyzed.Cells(GCount, (AnWeekCol + 1)) = 1
                End If
            End If
        
            If Analyzed.Cells(i, "C") = Analyzed.Cells(i + 1, "C") Then
                Analyzed.Cells(GCount, (AnWeekCol + 1)) = Analyzed.Cells(GCount, (AnWeekCol + 1)) + 1
                Analyzed.Cells(GCount, AnWeekCol) = Analyzed.Cells(i, "C")
            Else
                If (Analyzed.Cells(i, "C") <> Analyzed.Cells(i + 1, "C")) And (Analyzed.Cells(i, "C") <> Analyzed.Cells(i - 1, "C")) Then
                    Analyzed.Cells(GCount, (AnWeekCol + 1)) = 1
                    Analyzed.Cells(GCount, AnWeelCol) = Analyzed.Cells(i, "C")
                End If
                GCount = GCount + 1
            End If
        Next i
 
Hi,

is GCount set to 1 before the loop starts?
How is Analyzed dimensioned and set?

Cheers,

Roel
 
Yes GCount was intilized to 1 before loop start but solution was easier than that.
The line below had a wrong variable in it.
Analyzed.Cells(GCount, AnWeelCol) = Analyzed.Cells(i, "C")

AnWeelCol needed to be AnWeekCol

Me and my asking questions that get solved on thier own
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top