If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VBA: Getting cell address of maximum value in range

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-11, 14:29
scrtchmstj scrtchmstj is offline
Registered User
 
Join Date: Jan 2009
Location: Louisiana, United States
Posts: 138
VBA: Getting cell address of maximum value in range

I have a range of numbers F9:F33. I'd like to have VBA find the cell address for the cell with the maximum value. I tried using a combination of "Application.WorksheetFunction"s to recreate the excel formula = Cell("address", Index(F9:F33, Match(Max(F9:F33),F9:F33,0))) but apparently Application.WorsheetFunction does not support the Excel "Cell" function. Any ideas how I could go about this? Thanks! Josh
Reply With Quote
  #2 (permalink)  
Old 02-11-11, 08:20
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

Being as yiu are using VBA I assume you have not objection to using code, such as
Code:
Function MaxAddress(ByRef ThisRange As Range) As String
    Dim cel As Range
    For Each cel In ThisRange
        If cel = Application.WorksheetFunction.Max(ThisRange) Then MaxAddress = cel.Address
    Next cel
End Function
Sub TestFunction()
    MsgBox MaxAddress(Range("F9:F33"))
End Sub
I don't normally use 'Application.WorksheetFunction' but it works so why not!

HTH


MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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