PDA

View Full Version : Subscript out of Range



paleaux
08-12-2011, 11:01 AM
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:

Sub Test()
Worksheets("Gate_Log").Range("A2:B300").Copy Worksheets("Timesheet").Range("B2")
Worksheets("Gate_Log").Range("D2:D300").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("D2:D300").Copy Worksheets("Material").Range("B2")
Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("Equipment").Range("A2")
Worksheets("Gate_Log").Range("D2:D300").Copy Worksheets("Equipment").Range("B2")
Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("ThirdParty").Range("A2")
Worksheets("Gate_Log").Range("D2:D300").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
Can anyone give me a hand with this, Thanks...

Bob Phillips
08-12-2011, 11:14 AM
Impossible to say if the sheets all exist as you say. Can you post the workbook?

paleaux
08-12-2011, 11:37 AM
Here you go and thanks again for the help....

GTO
08-12-2011, 08:21 PM
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:
Worksheets("Gate_Log").Range("A2:A300").Copy Worksheets("Third Party").Range("A2")
Worksheets("Gate_Log").Range("D2:D300").Copy Worksheets("ThirdParty").Range("B2")