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))
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Special-K99

Well-known Member
Joined
Nov 7, 2006
Messages
8,350
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
 

Conoro1894

New Member
Joined
Nov 7, 2016
Messages
9
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
Office Version
  1. 365
Platform
  1. Windows
Is the value in the range 'sheet' the name of a worksheet in the active workbook?
 

Conoro1894

New Member
Joined
Nov 7, 2016
Messages
9

ADVERTISEMENT

No it is the name of a column in the DATA worksheet. I have named this column as sheet
 

Special-K99

Well-known Member
Joined
Nov 7, 2006
Messages
8,350
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:

Conoro1894

New Member
Joined
Nov 7, 2016
Messages
9

ADVERTISEMENT

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
 

Conoro1894

New Member
Joined
Nov 7, 2016
Messages
9
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.
 

Conoro1894

New Member
Joined
Nov 7, 2016
Messages
9
Still haven't found a solution to this problem. If anyone has any new ideas,they'd be much appreciated.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,400
Messages
5,528,511
Members
409,821
Latest member
decibelpilot

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top