Consulting

Results 1 to 5 of 5

Thread: Solved: Run-time error 1004 ... What am I missing?

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Posts
    76
    Location

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

    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

    [vba]
    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

    [/vba]

    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!!!

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    You don't give a value to QueryRow until here.
    [vba]QueryRow = QueryRow + 1 [/vba]
    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.

  3. #3
    VBAX Regular
    Joined
    Oct 2007
    Posts
    76
    Location
    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!!!

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    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?

  5. #5
    VBAX Regular
    Joined
    Oct 2007
    Posts
    76
    Location
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •