Loop to mark first max value of a range, then second, third, etc.

loderdodger

New Member
Joined
Jun 9, 2008
Messages
7
Hi all,
I'm trying to create a macro but am having trouble with the loop function. I've tried to go off of examples online but I can't figure it out. I would really appreciate any tips or examples I could work with.

What I am trying to do is take a range of numbers (iArray) find which one is the max value, then put a 1 in the cell next to that one. Then loop to find the next largest value and put a 2 next to that one, then the third largest and a 3 next to that one, etc. From my lack of knowledge in VBA the only way I can think of doing it is sorting the column, then pasting 1,2,3 and so on in the cell next to each value, but I was hoping to do something a little cleaner with a loop if possible.

Thanks for any help!



This is all I have so far:


Sub Optimize()

Dim iArray As Variant
iArray = Range("A1:A100")

Dim iArrayMax As Integer
iArrayMax = WorksheetFunction.max(iArray)



End Sub
 

Forum statistics

Threads
1,226,799
Messages
6,193,068
Members
453,773
Latest member
bclever07

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