VBA ONLY: Alter Array Elements

jc0r

Board Regular
Joined
Mar 16, 2009
Messages
123
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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,659
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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)
 

jc0r

Board Regular
Joined
Mar 16, 2009
Messages
123
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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,570
Messages
5,770,915
Members
425,652
Latest member
Pemby

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
Top