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
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