VBA ONLY: Alter Array Elements

jc0r

Board Regular
Joined
Mar 16, 2009
Messages
124
Hi all

I have a script that generates an array in VBA. The array is multidimensional, always 10 columns wide but is dynamic with the amount of rows. In the below example it is currently getting elements for 3 rows

array.png


What i would like to be able to do is run a script which will alter the elements in the array index that has the highest value in column 9. So in the above example MyVar(3) has the highest value in column 9 (0.17628...).

From there i would like a script to do, for example:

MyArr(3,2) = MyArr(3,2) x 2
MyArr(3,3) = MyArr(3,3) +1
etc.

Hope this make sense,

Many thanks in advance
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This is untested (because I did not feel like typing in all the data in your posted picture into a worksheet), but I think it should work. I have also provided the Dim statement for declaring the variables I used in case you declare all of your variables (which you should always do).
VBA Code:
Dim R As Long, Indx As Long, Max As Double

For R = 1 To UBound(MyArray)
  If MyArray(R, 9) > Max Then Indx = R
Next
MyArray(Indx, 2) = 2 * MyArray(Indx, 2)
MyArray(Indx, 3) = 1 + MyArray(Indx, 3)
 
Upvote 0
Thats great, thankyou Rick. I don't suppose you could suggest how i would get to the 2nd, 3rd next highest once conditions are met could you please?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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