C
CompleteNewb
First off, if you know an easier way to fill a 1-D array with a 1-D range's
values, then add to it from another 1-D range, please let me know. Someone
posted that ArrayName = Range("A1:A5") would put those 5 values in the
array, but it was not working for me. What I'm doing is assigning specified
range of cell's values to an array, then assigning another specified range'
values to it aftr a little more operation. My problem is with my first
assignment, however:
I have this:
dim ElementList() as variant
StartRange = Range(FoundIt.Address).Offset(3, -2).Address
EndRange = Range(StartRange).End(xlDown).Address
I've already done some variable assignments, you can trust that these ranges
being assigned is working; StartRange is A8, EndRange is A11
I then populate ElementList array with the values of the cells From A8 to
A11:
For Each Cell In Range(StartRange, EndRange)
ReDim Preserve ElementList(0 To i)
ElementList(i) = Cell.Value
i = i + 1
Next Cell
Now, as I'm looping through the cells in this range, I can debug.print each
value; so the array is indeed getting all the cell values. HOWEVER, when I
then execute this line:
Worksheets("Sheet1").Range("C3:C" & UBound(ElementList) + 1) =
Application.WorksheetFunction.Transpose(ElementList)
I only get 2 of the items in the array. When I change the "+1" to "+3" I
get all of them. Why would my range that I'm filling with my array have to
be 3 cells bigger than the number of values in my array in order to get all
the values? There are no blanks in the array, when I try to debug.print(4)
I get subscript out of range, because there are only 0 through 3 items in
there.
Can anyone explain why this is happening? And please, remember, if there's
an easier way to assemble an array with a range's cell values and then
output it to a column, I'm all ears. Big time.
Thanks for reading
values, then add to it from another 1-D range, please let me know. Someone
posted that ArrayName = Range("A1:A5") would put those 5 values in the
array, but it was not working for me. What I'm doing is assigning specified
range of cell's values to an array, then assigning another specified range'
values to it aftr a little more operation. My problem is with my first
assignment, however:
I have this:
dim ElementList() as variant
StartRange = Range(FoundIt.Address).Offset(3, -2).Address
EndRange = Range(StartRange).End(xlDown).Address
I've already done some variable assignments, you can trust that these ranges
being assigned is working; StartRange is A8, EndRange is A11
I then populate ElementList array with the values of the cells From A8 to
A11:
For Each Cell In Range(StartRange, EndRange)
ReDim Preserve ElementList(0 To i)
ElementList(i) = Cell.Value
i = i + 1
Next Cell
Now, as I'm looping through the cells in this range, I can debug.print each
value; so the array is indeed getting all the cell values. HOWEVER, when I
then execute this line:
Worksheets("Sheet1").Range("C3:C" & UBound(ElementList) + 1) =
Application.WorksheetFunction.Transpose(ElementList)
I only get 2 of the items in the array. When I change the "+1" to "+3" I
get all of them. Why would my range that I'm filling with my array have to
be 3 cells bigger than the number of values in my array in order to get all
the values? There are no blanks in the array, when I try to debug.print(4)
I get subscript out of range, because there are only 0 through 3 items in
there.
Can anyone explain why this is happening? And please, remember, if there's
an easier way to assemble an array with a range's cell values and then
output it to a column, I'm all ears. Big time.
Thanks for reading