vba code

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

what am i doing wrong here??

Sub testtt()
row = Sheets("DATA").WorksheetFunction.max(Range
("a10:a20"))

MsgBox row

End Sub
 
Paul,
what am i doing wrong here??

WorksheetFunction is a property of the Application, not the Worksheet, and
MAX returns the maximum value, not the row where the max is located.

To get the row, you need to use MATCH after finding the MAX, though you
could do it in one step.

Sub testtt2()
myMax = Application.WorksheetFunction.Max(Sheets("DATA").Range("a10:a20"))
MsgBox "The maximum value is " & myMax
row = Application.WorksheetFunction.Match(myMax,
Sheets("DATA").Range("a10:a20"), False) + 9
MsgBox "The maximum value is found in row " & row
End Sub

HTH,
Bernie
MS Excel MVP
 
That wrapped badly. Try this one:

Sub testtt2()
myMax = Application.WorksheetFunction.Max _
(Sheets("DATA").Range("a10:a20"))
MsgBox "The maximum value is " & myMax
Row = Application.WorksheetFunction.Match _
(myMax, Sheets("DATA").Range("a10:a20"), False) + 9
MsgBox "The maximum value is found in row " & Row
End Sub

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top