LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and select maximum value in a range


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

--
Mcneiliu
-----------------------------------------------------------------------
Mcneilius's Profile: http://www.excelforum.com/member.php...fo&userid=1377
View this thread: http://www.excelforum.com/showthread.php?threadid=46855

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBA to find a value and select a range AlexJarvis Excel Worksheet Functions 4 April 27th 10 08:38 PM
select date range then find average of values in another cell rob117 Excel Worksheet Functions 3 May 3rd 07 03:34 PM
find maximum Frank Drost Excel Discussion (Misc queries) 7 January 18th 06 02:23 AM
find which column has the maximum value Frank Drost Excel Discussion (Misc queries) 2 December 15th 05 01:09 AM
How to Select a relative range with Using "Find" and Offset() Dennis Excel Discussion (Misc queries) 7 July 27th 05 03:57 PM


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"