Error 9: Subscript out of range

Conoro1894

New Member
Joined
Nov 7, 2016
Messages
9
The following is just part of my code. i am getting an Error 9: Subscript out of range. I've tried a few things in order to correct this but nothing seems to change it.

r = 2 c = 2
i = 2
LastRowNumber = xlLastRow(Sheets("Data"))
Do While Sheets("DATA").Cells(r, 4) <> ""

Sheets("DATA").Activate

Sheets("DATA").Cells(i, 10).Name = "sheet"
Sheets("DATA").Cells(c, 11).Name = "cell"
Sheets("DATA").Cells(r, 4).Copy
Sheets(Range("sheet").Value).Activate
Range(Range("cell").Value).Select 'Activate
CenterOnCell Range((Range("cell").Value))
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
r=2 c=2

Shouldn't that be

Code:
r=2: c=2

Subscript out of range can also mean the sheet doesn't exist

Are you sure this is correct?
Code:
Sheets(Range("sheet").Value).Activate
 
Upvote 0
Sorry,I should have pointed out where the issue was coming from.
This is the line of code that is bringing up the error,I need to change this somehow.
Sheets(Range("sheet").Value).Activate
 
Upvote 0
Is the value in the range 'sheet' the name of a worksheet in the active workbook?
 
Upvote 0
For this to work

Code:
Sheets(Range("sheet").Value).activate

Range("sheet").Value should be the name of an existing sheet not a column
 
Last edited:
Upvote 0
Ok that helps but it also means the rest of my code doesnt run either.
I have posted the relevant parts of my code belowe to see if it helps with the context of my problem.



Application.ScreenUpdating = False


Dim r As Integer
Dim c As Integer
Dim i As Integer
Dim LastRowNumber As Integer
Dim shtCount As Integer
With Application
.ReferenceStyle = xlR1C1
End With

r = 2
c = 2
i = 2
LastRowNumber = xlLastRow(Sheets("Data"))
Do While Sheets("DATA").Cells(r, 4) <> ""

Sheets("DATA").Activate

Sheets("DATA").Cells(i, 10).Name = "sheet"
Sheets("DATA").Cells(c, 11).Name = "cell"
Sheets("DATA").Cells(r, 4).Copy




Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
Upvote 0
Ok that helps but it also means the rest of my code doesnt run either.
I have posted the relevant parts of my code belowe to see if it helps with the context of my problem.



Application.ScreenUpdating = False


Dim r As Integer
Dim c As Integer
Dim i As Integer
Dim LastRowNumber As Integer
Dim shtCount As Integer
With Application
.ReferenceStyle = xlR1C1
End With

r = 2
c = 2
i = 2
LastRowNumber = xlLastRow(Sheets("Data"))
Do While Sheets("DATA").Cells(r, 4) <> ""

Sheets("DATA").Activate

Sheets("DATA").Cells(i, 10).Name = "sheet"
Sheets("DATA").Cells(c, 11).Name = "cell"
Sheets("DATA").Cells(r, 4).Copy
Sheets(Range("sheet").Value).Activate
Range(Range("cell").Value).Select 'Activate

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

I changed a bit of code to include where my problem is occurring.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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