ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Arrays: Subscript out of range (https://www.excelbanter.com/excel-programming/323358-arrays-subscript-out-range.html)

nortor

Arrays: Subscript out of range
 
Hello all :-)


For some reason I get stuck on some Subscript out of range error when
running this code.

I wonder if I might have dim(ensioned) as wrong variant or something

Please help me solve this... (btw, the first sheet is about 6000 rows,
and the second is about 1800 rows)

Here is the code:


Sheets("Analyse").Select
Cells(3, 1).Activate
Dim myArray() As Variant
Dim dSett1() As Variant
Dim dSett2() As Variant
Dim dSett3() As Variant

cnt1 = cnt1 + 1

ReDim dSett1(3 To cnt1)
ReDim dSett2(2 To cnt2, 1 To 26)
ReDim myArray(3 To cnt1, 1 To 9)

For i = 3 To cnt1
dSett1(i) = Sheets("Analyse").Cells(i, 1).Value
Next i

For i = 2 To cnt2
For j = 1 To 26
dSett2(i, j) = Sheets("Datasett2").Cells(i, j).Value
Next j
Next i

For i = 3 To cnt1
For k = 2 To cnt2
If dSett1(i) = dSett2(k, 1) Then
For j = 1 To 9
myArray(i, j) = dSett2(i - 1, (9 + j))
Next j
End If
Next k
Next i



Best regards,
-Nortor



Tushar Mehta

Arrays: Subscript out of range
 
What line generates the error? What is/are the value/s of the
subscript/s at that point?

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hello all :-)


For some reason I get stuck on some Subscript out of range error when
running this code.

I wonder if I might have dim(ensioned) as wrong variant or something

Please help me solve this... (btw, the first sheet is about 6000 rows,
and the second is about 1800 rows)

Here is the code:


Sheets("Analyse").Select
Cells(3, 1).Activate
Dim myArray() As Variant
Dim dSett1() As Variant
Dim dSett2() As Variant
Dim dSett3() As Variant

cnt1 = cnt1 + 1

ReDim dSett1(3 To cnt1)
ReDim dSett2(2 To cnt2, 1 To 26)
ReDim myArray(3 To cnt1, 1 To 9)

For i = 3 To cnt1
dSett1(i) = Sheets("Analyse").Cells(i, 1).Value
Next i

For i = 2 To cnt2
For j = 1 To 26
dSett2(i, j) = Sheets("Datasett2").Cells(i, j).Value
Next j
Next i

For i = 3 To cnt1
For k = 2 To cnt2
If dSett1(i) = dSett2(k, 1) Then
For j = 1 To 9
myArray(i, j) = dSett2(i - 1, (9 + j))
Next j
End If
Next k
Next i



Best regards,
-Nortor




nortor

Arrays: Subscript out of range
 
Hello!

This line (fifth last one)

myArray(i, j) = dSett2(i - 1, (9 + j))

i is then 1933 and j is 1

I think the error is in the last part(after the equal sign)


Cheers
NorTor



On Wed, 16 Feb 2005 20:13:17 GMT, Tushar Mehta
wrote:

What line generates the error? What is/are the value/s of the
subscript/s at that point?



swisse

Arrays: Subscript out of range
 
Write in the Declaration area:
Option Base 1

Swisse

NickHK

Arrays: Subscript out of range
 
nortor,
Check you value of cnt2.
It should have a maximum value of cnt1-1, by the time the error occurs.

NickHK

"nortor" wrote in message
...
Hello!

This line (fifth last one)

myArray(i, j) = dSett2(i - 1, (9 + j))

i is then 1933 and j is 1

I think the error is in the last part(after the equal sign)


Cheers
NorTor



On Wed, 16 Feb 2005 20:13:17 GMT, Tushar Mehta
wrote:

What line generates the error? What is/are the value/s of the
subscript/s at that point?






All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com