#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default vba code

what am i doing wrong here??

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

MsgBox row

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default vba code

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").R ange("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

"Paul" wrote in message
...

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

MsgBox row

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default vba code

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

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
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").R ange("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

"Paul" wrote in message
...

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

MsgBox row

End Sub





Reply
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM
option buttons run Click code when value is changed via VBA code neonangel Excel Programming 5 July 27th 04 08:32 AM


All times are GMT +1. The time now is 12:36 AM.

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

About Us

"It's about Microsoft Excel"