array help needed

RET79

Well-known Member
Joined
Mar 19, 2002
Messages
526
Hi, I have this following piece of code which assignes a range to an array, take a look:



Dim rngcells1 as range

ReDim arrcells1(0 To i, 0 To rngcells1.Rows.Count - 1)

For k = 1 To i
For cellx = 1 To rngcells1.Rows.Count - 1

arrcells1(k - 1, cellx - 1) = Cells(rngcells1(cellx + 1, 2), rngcells1(cellx + 1, 3)).Offset(0, tl8 * (k - 1)).Value
Debug.Print arrcells1(k - 1, cellx - 1)

Next cellx
Next k

But now, as I have 12 dynamic ranges and not just 1, I have defined the ranges like this:

Dim rngcells(1 To 12) As Range
Dim rngGroup As Range


'just defines the dynamic range

Set rngGroup = [E9].Offset(, (5 * (i - 1)))
Set rngcells(i) = Range(Range(rngGroup, rngGroup.End(xlToRight)), Range(rngGroup, rngGroup.End(xlToRight)).End(xlDown))
If rngcells(i).Rows.Count< 42 Then
For k = 2 To rngcells(i).Rows.Count
Debug.Print rngcells(i)(k, 1)
Next k
End If


So, back in my initial code, I just have to replace rngCells1 by rngCells(p) say and put all the code in a loop from p = 1 to 12 for it to work for the 12 dynamic ranges.

But, how do I adjust the array assignment now, i.e. the line

arrcells1(k - 1, cellx - 1) = Cells(rngcells1(cellx + 1, 2), rngcells1(cellx + 1, 3)).Offset(0, tl8 * (k - 1)).Value

Replacing rngcells1 with rngcells(p) works ok. However, I am not sure what to change arrcells1 to. I have tried changing it to arrcells(p) likewise but it doesn't seem to work. Have I defined the array wrongly or something? I would have thought that

arrayCells(p)(k - 1, cellx - 1) = Cells(rngcells(p)(cellx + 1, 2), rngcells(p)(cellx + 1, 3)).Offset(0, tl8 * (k - 1)).Value

would work, but it doesn't for me!

Also, just for completeness, I had this code just after the above, for just the one range case:

[B65336].End(xlUp).Offset(1, 0).Select
Range(Selection, Selection.Offset(i - 1, rngcells1.Rows.Count - 2)) = arrcells1

So, whatever this new array becomes, it must be able to be put onto a worksheet like that.

I hope I have not confused everyone too much.
Can anyone help me?? I would be most grateful!

Thanks,

RET79
This message was edited by RET79 on 2002-04-03 09:06
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,214,808
Messages
6,121,681
Members
449,048
Latest member
81jamesacct

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