PDA

View Full Version : Solved: Run-time error 1004 ... What am I missing?



NateW
10-17-2007, 12:54 PM
Hi, Folks...

I'm trying to do what I thought would be a very simple macro - sort of the basis for something more complicated
I'm planning, but of course I'm getting hung up on the first step. The following code produces the following error:

Run-time error 1004: Application-defined or Object-defined error


Sub Calculate_KPI()

Dim DataRow, QueryRow As Integer

Application.ScreenUpdating = False

DataRow = 2
ScheduleRow = 2

Sheets("Query Results").Activate



Do Until Sheets("Data").Cells(DataRow, 1).Value = ""
' THIS IS IS THE LINE THE DEBUGGER POINTS TO AFTER ERROR:
Sheets("Query Results").Cells(QueryRow, 1).Value = Sheets("Data").Cells(DataRow, 7).Value
Sheets("Query Results").Cells(QueryRow, 2).Value = Sheets("Data").Cells(DataRow, 8).Value 'Order Number
Sheets("Query Results").Cells(QueryRow, 3).Value = Sheets("Data").Cells(DataRow, 9).Value 'Order details

QueryRow = QueryRow + 1
DataRow = DataRow + 1
Loop

Application.ScreenUpdating = True

End Sub



All sheets are within the same workbook, and I've checked to see if all names match up, which I'm *pretty*
sure they do - but you know how sometimes that can be missed... What am I missing?

Thanks for your help!!!

Norie
10-17-2007, 12:57 PM
You don't give a value to QueryRow until here.
QueryRow = QueryRow + 1
So in the first iteration of the loop QueryRow will be 0 and last time I looked there wasn't a row 0 in Excel.:)

NateW
10-17-2007, 01:03 PM
LOL I knew it would be something that would embarrass me... I took this code from something else I was using, that's the one place I didn't change the name properly - if you look, ScheduleRow should have been QueryRow.

I promise, before I ask a question that will totally expose me as a dumbass, I'll quadruple check my references...ARG!!

Thank you!!!

Norie
10-17-2007, 01:08 PM
NateW

No problem, we all make mistakes.:)

I've not fully examined your code but are you sure this couldn't be done in one go without a loop?

NateW
10-17-2007, 01:12 PM
It could as is, but I have to build some logic into it - I don't want all the values in the range, I'm going to have to pick and choose based on a few criteria. I could be wrong - really, I'm a novice - but I think the loop is the best way to go in this case. Am I wrong?