Consulting

Results 1 to 4 of 4

Thread: Subscript out of Range

  1. #1
    VBAX Regular
    Joined
    Aug 2011
    Posts
    17
    Location

    Subscript out of Range

    I am getting an error when I run my code

    Error 9 Subscript out of Range..

    Normally this would be due to the fact the worksheets in question are not named, but all of my worksheets are named.

    Code:

    [vba]Sub Test()
    Worksheets("Gate_Log").Range("A2:B300").Copy Worksheets("Timesheet").Range("B2")
    Worksheets("Gate_Log").Range("D2300").Copy Worksheets("Timesheet").Range("D2")
    Worksheets("Gate_Log").Range("E2:E300").Copy Worksheets("Timesheet").Range("N2")
    Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("Material").Range("A2")
    Worksheets("Gate_Log").Range("D2300").Copy Worksheets("Material").Range("B2")
    Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("Equipment").Range("A2")
    Worksheets("Gate_Log").Range("D2300").Copy Worksheets("Equipment").Range("B2")
    Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("ThirdParty").Range("A2")
    Worksheets("Gate_Log").Range("D2300").Copy Worksheets("ThirdParty").Range("B2")


    Dim OneCell As Range
    For Each OneCell In Range(Range("N2"), Range("N" & Rows.Count).End(xlUp))
    OneCell.Formula = "=Round(" & OneCell.Value & ",0)"
    Next OneCell
    End Sub
    [/vba] Can anyone give me a hand with this, Thanks...
    Last edited by Aussiebear; 08-16-2011 at 12:24 AM. Reason: Added vba tags to code

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Impossible to say if the sheets all exist as you say. Can you post the workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Aug 2011
    Posts
    17
    Location
    Here you go and thanks again for the help....
    Attached Files Attached Files

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Paleaux,

    In the worksheets, look at Material. Double-click the tab and you will see that you included a trailing space.

    In the code, Third Party is missing a space:
    [vba] Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("Third Party").Range("A2")
    Worksheets("Gate_Log").Range("D2300").Copy Worksheets("ThirdParty").Range("B2")[/vba]

Posting Permissions

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