Error 9: Subscript Out of Range

billyheanue

Board Regular
Joined
Jul 13, 2015
Messages
109
Whats good homies,

I am a excel noob and I get this error 9 when I try to run this. Since it doesnt specify what line is actually wrong, Im wondering if any of the VB Guru's can point me in the right direction in terms of whats wrong with this code? Very confused!:mad:

Code:
Private Sub CommandButton8_Click()


Dim x As Integer
Dim y As Integer
Dim colindexval As Double
Dim resizeval As Double


resizeval = Sheet1.Cells(19, 12).Value
colindexval = Sheet1.Cells(16, 12).Value
Sheet9.Range(x, y).Resize(resizeval, 1).Formula = "=VLOOKUP(Sheet1!B16,Sheet2!" _
    & Sheets("Sheet2").Range("A12").CurrentRegion.Address & ",Sheet1!L$29,FALSE)"
    
End Sub
 
Counting from the left what number tab would the 2 sheets numbers be?
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Does the code below work? if yes copy and paste the sheet names it puts in the immediate window into the code I previously posted.
If you can't see the immediate window then press Ctrl+G. (and yes I do hate typing code on a phone)


Code:
Sub Testit()
Sheets(14).Range("G2:G8561")
    .Copy Sheets(15).Range("C10")
End With
Debug.Print Sheets(14).Name
Debug.Print Sheets(15).Name
End Sub
 
Upvote 0
I get a compile error when I try to run that code. It says "Invalid or unqualified reference". It highlights the .Copy in the second line.
 
Upvote 0
Does the code below work? if yes copy and paste the sheet names it puts in the immediate window into the code I previously posted.
If you can't see the immediate window then press Ctrl+G. (and yes I do hate typing code on a phone)


Code:
Sub Testit()
Sheets(14).Range("G2:G8561")
    .Copy Sheets(15).Range("C10")
End With
Debug.Print [B][COLOR="#FF0000"]"< &"[/COLOR][/B] Sheets(14).Name [B][COLOR="#FF0000"]"& >"[/COLOR][/B]
Debug.Print [B][COLOR="#FF0000"]"< &"[/COLOR][/B] Sheets(15).Name [B][COLOR="#FF0000"]"& >"[/COLOR][/B]
End Sub
I would add what I show in red above so you can see if there are any leading or trailing "invisible" characters.
 
Upvote 0
I would add what I show in red above so you can see if there are any leading or trailing "invisible" characters.
Try this modification of Mark's code...
Code:
Sub Testit()
  Sheets(14).Range("G2:G8561").Copy Sheets(15).Range("C10")
  End With
  Debug.Print "< &"; Sheets(14).Name; "& >"
  Debug.Print "< &"; Sheets(15).Name; "& >"
End Sub
 
Upvote 0
I get: "Run-time error '1004': Application-defined or object-defined error".

Just want to take this moment to thank the two of you for all the help.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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