M
Mcneilius
Hi all
I'm trying to get a macro to find and select cell that contains th
maximum value of 3 selected cells.
Say cells A1 to A3 contain 2.45, 3.36, 2.78 (these numbers can change)
the macro currently looks like:
Sub FindMax()
Range("A1").Activate
StartCell = ActiveCell.Offset(0, 0).Address
EndCell = ActiveCell.Offset(0, 2).Address
Range(StartCell, EndCell).Select
Dim WorkRange As Range
Set WorkRange = Selection
MaxVal = Application.Max(WorkRange)
On Error Resume Next
Workrange.Find(What:=MaxVal, _
After:=Workrange.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False _
).Select
If Err <> 0 Then MsgBox "Max value was not found: " & MaxVal
End Sub
The code seems to work well on some selections, and not on others.
Sometimes there is a unique maximum of, say, 3.36 and it will say "Ma
Value was not found: 3.36" !?!?
Please, does anyone have any ideas on where I'm going wrong?
Thanks for your time
Nei
I'm trying to get a macro to find and select cell that contains th
maximum value of 3 selected cells.
Say cells A1 to A3 contain 2.45, 3.36, 2.78 (these numbers can change)
the macro currently looks like:
Sub FindMax()
Range("A1").Activate
StartCell = ActiveCell.Offset(0, 0).Address
EndCell = ActiveCell.Offset(0, 2).Address
Range(StartCell, EndCell).Select
Dim WorkRange As Range
Set WorkRange = Selection
MaxVal = Application.Max(WorkRange)
On Error Resume Next
Workrange.Find(What:=MaxVal, _
After:=Workrange.Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False _
).Select
If Err <> 0 Then MsgBox "Max value was not found: " & MaxVal
End Sub
The code seems to work well on some selections, and not on others.
Sometimes there is a unique maximum of, say, 3.36 and it will say "Ma
Value was not found: 3.36" !?!?
Please, does anyone have any ideas on where I'm going wrong?
Thanks for your time
Nei