Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find cell location of max value in column


HI,

The following macro finds the max value and writes it to a file. I
would also like to know the cell location where the max value was found
(a25, for example). I'm stumped. The MS KB article has an solution,
which is pasted in below, but I cannot get it to worl. Suggestions on
getting that to work or another solution?

Tx, Rob

MY MACRO
Sub Macro1()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A10:A250")
top_max_val = Application.WorksheetFunction.Max(myRange)
MsgBox top_max_val
Open "c:\testfile.txt" For Append As #1
'Write #1, top_max_loc, top_max_val, ActiveWorkbook.FullName '
Write blank line.
Close #1
'ActiveWorkbook.Close
End Sub

The MS KB solution to finding the cell location:
To return the address of a cell in a column (in this example, column A,
cells A1:A10), use the appropriate formula in the following table.
For this
address Use this formula

------------------------------------------------------------------------
Cell with
largest
value
=CELL("address",OFFSET(A1,MATCH(MAX(A1:A10),A1:A10 ,0)-1,0))

Any help much appreciated. As usual, deadline looms.

Rob


--
rroach
------------------------------------------------------------------------
rroach's Profile: http://www.excelforum.com/member.php...o&userid=21093
View this thread: http://www.excelforum.com/showthread...hreadid=376682

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find cell location of max value in column


Hi Rob,

=CELL("address",OFFSET(A1,MATCH(MAX(A1:A10),A1:A10 ,0)-1,0))

works properly.
Just check that range A1:A10 is the range which holds your data, and A1
is the first cell in the range. Replace these with correct values if
they are different from your case.

This is a simple worksheet formula. Do you want a VBA solution
instead.

In VBA you can call the same formula by using the evaluate e.g.
=
EVALUATE("CELL(""address"",OFFSET(A1,MATCH(MAX(A1: A10),A1:A10,0)-1,0))")

Mangesh


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=376682

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find cell location of max value in column


'evaluate' is what i was missing.

thanks!

Rob


--
rroach
------------------------------------------------------------------------
rroach's Profile: http://www.excelforum.com/member.php...o&userid=21093
View this thread: http://www.excelforum.com/showthread...hreadid=376682

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find cell location of max value in column


Thanks for the feedback. You could also do it in a different manner, but
since you had a worksheet function already, you might as well use it in
VBA.

Mangesh


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=376682

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find cell location of max value in column


Extending the previous question. I am too dense to see what I am doin
wrong in the following VBA statement. I'd like to create a variabl
that contains the location of the last cell.

1. Then create a range that is from 250 cells before last cell to las
cell.

2. Then repeat what Mangesh helped me figure out form before--find th
max in that range. Having trouble passing range variables to th
statements? Ideas?

1. bot_max_loc
Evaluate("CELL(""address"",Range("A1").SpecialCell s(xlCellTypeLastCell).Row))--wan
to get location (a:767) of last cell, then use that in a range?

2. top_max_loc
Evaluate("CELL(""address"",OFFSET(A10,MATCH(MAX(a1 0:a250),a10:a250,0)-1,0))")--ho
to substitute named ranges for a10:a250?

Thanks in advance.

Ro

--
rroac
-----------------------------------------------------------------------
rroach's Profile: http://www.excelforum.com/member.php...fo&userid=2109
View this thread: http://www.excelforum.com/showthread.php?threadid=37668



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default find cell location of max value in column

Sub Macro1()
Dim top_max_loc as Variant
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A10:A250")
top_max_val = Application.WorksheetFunction.Max(myRange)
top_max_Loc = application.Match(top_max_val,myrange,0)
top_max_Loc= myrange(top_max_loc).Address
MsgBox top_max_val
Open "c:\testfile.txt" For Append As #1
'Write #1, top_max_loc, top_max_val, ActiveWorkbook.FullName '
Write blank line.
Close #1
'ActiveWorkbook.Close
End Sub

--
Regards,
Tom Ogilvy


"rroach" wrote in
message ...

HI,

The following macro finds the max value and writes it to a file. I
would also like to know the cell location where the max value was found
(a25, for example). I'm stumped. The MS KB article has an solution,
which is pasted in below, but I cannot get it to worl. Suggestions on
getting that to work or another solution?

Tx, Rob

MY MACRO
Sub Macro1()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A10:A250")
top_max_val = Application.WorksheetFunction.Max(myRange)
MsgBox top_max_val
Open "c:\testfile.txt" For Append As #1
'Write #1, top_max_loc, top_max_val, ActiveWorkbook.FullName '
Write blank line.
Close #1
'ActiveWorkbook.Close
End Sub

The MS KB solution to finding the cell location:
To return the address of a cell in a column (in this example, column A,
cells A1:A10), use the appropriate formula in the following table.
For this
address Use this formula

------------------------------------------------------------------------
Cell with
largest
value
=CELL("address",OFFSET(A1,MATCH(MAX(A1:A10),A1:A10 ,0)-1,0))

Any help much appreciated. As usual, deadline looms.

Rob


--
rroach
------------------------------------------------------------------------
rroach's Profile:

http://www.excelforum.com/member.php...o&userid=21093
View this thread: http://www.excelforum.com/showthread...hreadid=376682



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default find cell location of max value in column

Sub Macro1()
Dim top_max_loc as Variant
Dim myRange As Range
With Worksheets("Sheet1")
Set myRange = .Range(.Cells(10,1),cells(rows.count,1).End(xlup))
top_max_val = Application.WorksheetFunction.Max(myRange)
top_max_Loc = application.Match(top_max_val,myrange,0)
top_max_Loc= myrange(top_max_loc).Address
MsgBox top_max_val
Open "c:\testfile.txt" For Append As #1
'Write #1, top_max_loc, top_max_val, ActiveWorkbook.FullName '
Write blank line.
Close #1
'ActiveWorkbook.Close
End Sub

continue to ignore if you prefer your much slower approach.



--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Sub Macro1()
Dim top_max_loc as Variant
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A10:A250")
top_max_val = Application.WorksheetFunction.Max(myRange)
top_max_Loc = application.Match(top_max_val,myrange,0)
top_max_Loc= myrange(top_max_loc).Address
MsgBox top_max_val
Open "c:\testfile.txt" For Append As #1
'Write #1, top_max_loc, top_max_val, ActiveWorkbook.FullName '
Write blank line.
Close #1
'ActiveWorkbook.Close
End Sub

--
Regards,
Tom Ogilvy


"rroach" wrote in
message ...

HI,

The following macro finds the max value and writes it to a file. I
would also like to know the cell location where the max value was found
(a25, for example). I'm stumped. The MS KB article has an solution,
which is pasted in below, but I cannot get it to worl. Suggestions on
getting that to work or another solution?

Tx, Rob

MY MACRO
Sub Macro1()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A10:A250")
top_max_val = Application.WorksheetFunction.Max(myRange)
MsgBox top_max_val
Open "c:\testfile.txt" For Append As #1
'Write #1, top_max_loc, top_max_val, ActiveWorkbook.FullName '
Write blank line.
Close #1
'ActiveWorkbook.Close
End Sub

The MS KB solution to finding the cell location:
To return the address of a cell in a column (in this example, column A,
cells A1:A10), use the appropriate formula in the following table.
For this
address Use this formula

------------------------------------------------------------------------
Cell with
largest
value
=CELL("address",OFFSET(A1,MATCH(MAX(A1:A10),A1:A10 ,0)-1,0))

Any help much appreciated. As usual, deadline looms.

Rob


--
rroach
------------------------------------------------------------------------
rroach's Profile:

http://www.excelforum.com/member.php...o&userid=21093
View this thread:

http://www.excelforum.com/showthread...hreadid=376682





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
Find cell location in a large list TVC Excel Discussion (Misc queries) 4 March 6th 08 07:02 PM
How to find out the cell location Lamb Chop Excel Discussion (Misc queries) 3 September 7th 06 12:22 PM
Find & replace a value in an unknown cell location mellowe Excel Discussion (Misc queries) 2 November 20th 05 09:17 PM
find location max value in column rroach Excel Discussion (Misc queries) 3 July 13th 05 10:27 PM
Find Cell and Copy adjacent value to another location JJalomo Excel Programming 2 March 8th 05 07:17 PM


All times are GMT +1. The time now is 08:31 PM.

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"