ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Array handling error (https://www.excelbanter.com/excel-programming/381765-re-array-handling-error.html)

RichardSchollar

Array handling error
 
Hi

It's not easy to make good suggestions when you can't see your full
code, but have you ReDimensioned the YearD() dynamic array prior to
attempting to place values in it?

Best regards

Richard


PALysiak wrote:
I am trying to extract all of the column 9 data in the GoodArray(), earlier
in the program it is filled with data (I checked the locals window, it is
dimensioned properly and filled with what I want). When I go to take the data
from cell or column 9 from a 2 dimensional array and do a "Left" operation on
the data string in the cell and put it in a 1 dimensional array, I get an
"Out of Range" error. I added the "Dummy" variable to see if the Left
function worked and it does. It just refuses to take the column in a two
dimensional array and put it into a one dimensional array. What am I doing
wrong?


Dim YearD() as variant
Dim A As String
Dim Dummy as String

Dummy = GoodArray(9, i)
A = Left(Dummy, 2)


YearD(i) = Left(Dummy, 2) 'Extract the year
YearD(i) = Right(YearD(i), 1)



Tom Ogilvy

Array handling error
 
Because you dimmed it as a dymanic array, but didn't assign any dimensions.
Now you use redim to assign the dimensions.

--
Regards,
Tom Ogilvy

"PALysiak" wrote in message
...
Yes, I believe that works.
If I had just Dim the variable a few lines before, why would I redim then?
Thanks very much for your quick response.

"RichardSchollar" wrote:

Hi

It's not easy to make good suggestions when you can't see your full
code, but have you ReDimensioned the YearD() dynamic array prior to
attempting to place values in it?

Best regards

Richard


PALysiak wrote:
I am trying to extract all of the column 9 data in the GoodArray(),
earlier
in the program it is filled with data (I checked the locals window, it
is
dimensioned properly and filled with what I want). When I go to take
the data
from cell or column 9 from a 2 dimensional array and do a "Left"
operation on
the data string in the cell and put it in a 1 dimensional array, I get
an
"Out of Range" error. I added the "Dummy" variable to see if the Left
function worked and it does. It just refuses to take the column in a
two
dimensional array and put it into a one dimensional array. What am I
doing
wrong?


Dim YearD() as variant
Dim A As String
Dim Dummy as String

Dummy = GoodArray(9, i)
A = Left(Dummy, 2)


YearD(i) = Left(Dummy, 2) 'Extract
the year
YearD(i) = Right(YearD(i), 1)






PALysiak

Array handling error
 
Obviously I am a rookie to this stuff.
When I dimmed it with () or empty array I thought I was assigning the
variable a dynamic array. Redimming does work.

Again thanks for your help, this was driving me nuts.

"Tom Ogilvy" wrote:

Because you dimmed it as a dymanic array, but didn't assign any dimensions.
Now you use redim to assign the dimensions.

--
Regards,
Tom Ogilvy

"PALysiak" wrote in message
...
Yes, I believe that works.
If I had just Dim the variable a few lines before, why would I redim then?
Thanks very much for your quick response.

"RichardSchollar" wrote:

Hi

It's not easy to make good suggestions when you can't see your full
code, but have you ReDimensioned the YearD() dynamic array prior to
attempting to place values in it?

Best regards

Richard


PALysiak wrote:
I am trying to extract all of the column 9 data in the GoodArray(),
earlier
in the program it is filled with data (I checked the locals window, it
is
dimensioned properly and filled with what I want). When I go to take
the data
from cell or column 9 from a 2 dimensional array and do a "Left"
operation on
the data string in the cell and put it in a 1 dimensional array, I get
an
"Out of Range" error. I added the "Dummy" variable to see if the Left
function worked and it does. It just refuses to take the column in a
two
dimensional array and put it into a one dimensional array. What am I
doing
wrong?


Dim YearD() as variant
Dim A As String
Dim Dummy as String

Dummy = GoodArray(9, i)
A = Left(Dummy, 2)


YearD(i) = Left(Dummy, 2) 'Extract
the year
YearD(i) = Right(YearD(i), 1)







All times are GMT +1. The time now is 11:41 PM.

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