Hi everyone, hoping for your expertise. I am working with a set of data and trying to create a macro that, based on the cells that are selected, will return the highest value with the first button click, the second highest value with the second button click, etc.
I have put together the below, which is providing the highest number of the selected cells and inputting it in the correct cell. However, in order to minimize the amount of code I need to write, I want to create a For loop that, after finding the cell range of the first highest number, will copy the value to B40 and then change the interior of the cell range from the selected cells that was used red. That way, when I click on the button again, the macro will ignore the red cell and find the next largest value in the selection and record that in B41, and so on and so forth.
Would really appreciate your help!!!
Sub Decider()
Set rng = Selection
newCell = 0
For Each cell In rng
If cell.Value > newHighest And cell.Interior.Color <> RGB(255, 0, 0) Then
newHighest = cell.Value
End If
Next
Range("B40") = newHighest
End Sub
I have put together the below, which is providing the highest number of the selected cells and inputting it in the correct cell. However, in order to minimize the amount of code I need to write, I want to create a For loop that, after finding the cell range of the first highest number, will copy the value to B40 and then change the interior of the cell range from the selected cells that was used red. That way, when I click on the button again, the macro will ignore the red cell and find the next largest value in the selection and record that in B41, and so on and so forth.
Would really appreciate your help!!!
Sub Decider()
Set rng = Selection
newCell = 0
For Each cell In rng
If cell.Value > newHighest And cell.Interior.Color <> RGB(255, 0, 0) Then
newHighest = cell.Value
End If
Next
Range("B40") = newHighest
End Sub