An error message

plainme

Board Regular
Joined
Mar 23, 2010
Messages
60
What does the following error message means?

Run-time error '9'
Subscript out of range

Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
can you post the code.
there are a number of different possibilities for this error from a misspelt sheet name to wrong number of variables in an array..
 
Upvote 0
Sure. I put a list of file names with path in "File Path". I intended to use the following code to open the workbook from "File Path" and copy some range from tabA and tabB to paste on tab 2011Data. Then, go to the next workbook from "File Path" to repeat the copying and pasting.

Many Thanks!


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim i As Integer
Dim WorkbookName As String
Dim RemoteWkbk As Excel.Workbook, CurrWkbk As Excel.Workbook

i = 1
While Len(Range("File Path").Offset(i, 0)) > 0

' Open workbook
WorkbookName = Workbooks("File Path").Offset(i, 0)
'Open workbook
Set RemoteWkbk = Workbooks.Open(WorkbookName)


' Copy contents
x = RemoteWkbk.Worksheets("tabA").Range("A9:B12").Value
y = RemoteWkbk.Worksheets("tabB)").Range("A8:D20").Value
' Paste contents
CurrWkbk.Worksheets("2011Data").Range("P1").Offset(13 * (i - 1), 0).Resize(UBound(x, 1), UBound(x, 2)) = x
CurrWkbk.Worksheets("2011Data").Range("R1").Offset(13 * (i - 1), 0).Resize(UBound(y, 1), UBound(y, 2)) = y

RemoteWkbk.Close False

i = i + 1
Wend

Application.ScreenUpdating = False
End Sub
 
Upvote 0
I fixed it but still have an error message:

Run-time error '1004':
Application-defined or object-defined error

Thanks!
 
Upvote 0
what line does it stop at (use debug)
 
Upvote 0
Not the cause of the error, but you have screenupdating = false at the beginning and end of your sub. Should one of those be true?
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top