Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default How to return row #

Hello,

Is there an efficient way to return the row # corresponding to the row that
contains the maximum value in a column range?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How to return row #

Hi Bing,

In VBA you can do it like this -

Sub GetMaxRow()
MsgBox MaxRow(Range("A1").EntireColumn)
End Sub

Function MaxRow(colrng As Range)
MaxRow = Application.Match(Application.Max(colrng), colrng, 0)
End Function

Or with a formula -

=MATCH(MAX(A:A),A:A,0)

Gary

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default How to return row #

How about

maxRow = ActiveCell.End(xlDown).Row

Regards
Rowan

"Bing" wrote:

Hello,

Is there an efficient way to return the row # corresponding to the row that
contains the maximum value in a column range?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to return row #

Gary,

This doesn't work if the range is a sub set of a column not starting at row
1. For instance, if rows 7,8,9 contain 100,200,300 your routine returns 3
not 9. This amendment fixes it

Function MaxRow(colrng As Range)
Dim idx As Long
idx = Application.Match(Application.Max(colrng), colrng, 0)
MaxRow = colrng.Cells(idx, 1).Row
End Function



--

HTH

RP
(remove nothere from the email address if mailing direct)


"GaryDK" wrote in message
oups.com...
Hi Bing,

In VBA you can do it like this -

Sub GetMaxRow()
MsgBox MaxRow(Range("A1").EntireColumn)
End Sub

Function MaxRow(colrng As Range)
MaxRow = Application.Match(Application.Max(colrng), colrng, 0)
End Function

Or with a formula -

=MATCH(MAX(A:A),A:A,0)

Gary



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default How to return row #

Hi gentlemen.

Just wanted to say thanks very much for all of your helpful feedback.

Cheers,
Bing
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
Return date if in range, else return blank LisaL Excel Worksheet Functions 1 July 22nd 09 03:23 PM
Compare Value in Cell 1 to a List, Return Value if Match otherwise Return Null Ben Excel Discussion (Misc queries) 2 March 15th 07 01:02 AM
LOOKUP and return the column heading for IF/THEN return for False NN Excel Discussion (Misc queries) 1 October 6th 06 11:24 AM
check if reference exists, then return its value or return 0 doudou Excel Worksheet Functions 1 June 4th 05 09:17 PM
VBA Syntax for VLOOKUP to return array of return values Alan Beban[_3_] Excel Programming 7 August 5th 03 11:41 AM


All times are GMT +1. The time now is 07:28 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"