Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding cell address for minimum number


I'm trying to find the cell address for the lowest number in a column.
This does not seem to be working when the number is 0. Can someone
please help me figure out what's wrong with this code. It works when
there aren't any 0's in the column.

Thanks in advance
Trevor

Function MinAddress(rng)

Set rng = Columns(22)

' Sets variable equal to minimum value in the input range.
MinNum = Application.Min(rng)


' Loop to check each cell in the input range to see if equals the
' MinNum variable.
For Each cell In rng.Cells
If cell = MinNum Then
' If the cell value equals the MinNum variable it
' returns the address to the function and exits the loop.

MinAddress = cell.Address
Exit For
End If

Next cell

End Function


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Finding cell address for minimum number

Tre_Cool,

Try it as defined below, used like this from the worksheet

=MinAddress(V:V)

or like this from a macro

Dim myAdd As String
myAdd = MinAddress(Range("V:V"))
MsgBox myAdd

You really don't want to hardcode the column number like you did. Note that
it will return the address of the first instance of the minimum value, if
more than one exist.

HTH,
Bernie
MS Excel MVP


Function MinAddress(rng As Range) As String
MinAddress = rng(Application.Match( _
Application.Min(rng), rng, False)).Address
End Function


"Tre_cool" wrote in
message ...

I'm trying to find the cell address for the lowest number in a column.
This does not seem to be working when the number is 0. Can someone
please help me figure out what's wrong with this code. It works when
there aren't any 0's in the column.

Thanks in advance
Trevor

Function MinAddress(rng)

Set rng = Columns(22)

' Sets variable equal to minimum value in the input range.
MinNum = Application.Min(rng)


' Loop to check each cell in the input range to see if equals the
' MinNum variable.
For Each cell In rng.Cells
If cell = MinNum Then
' If the cell value equals the MinNum variable it
' returns the address to the function and exits the loop.

MinAddress = cell.Address
Exit For
End If

Next cell

End Function


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile:
http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Finding cell address for minimum number

I tried your function and it worked for positive, negative and zero. The
function is "sluggish". You have range as an argument and also set it inside
the function. As values are changed or added to column V, Excel isn't smart
enought to re-calculate the function because it does not see the input
changing.

I had to keep kicking it with CNTRL-ALT-F9.

You might consider removing the Set in the function and use it as
=MinAddress(V:V)
--
Gary''s Student


"Tre_cool" wrote:


I'm trying to find the cell address for the lowest number in a column.
This does not seem to be working when the number is 0. Can someone
please help me figure out what's wrong with this code. It works when
there aren't any 0's in the column.

Thanks in advance
Trevor

Function MinAddress(rng)

Set rng = Columns(22)

' Sets variable equal to minimum value in the input range.
MinNum = Application.Min(rng)


' Loop to check each cell in the input range to see if equals the
' MinNum variable.
For Each cell In rng.Cells
If cell = MinNum Then
' If the cell value equals the MinNum variable it
' returns the address to the function and exits the loop.

MinAddress = cell.Address
Exit For
End If

Next cell

End Function


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding cell address for minimum number


I don't understand where I'd put in MinAddress(Range("V:V"))? Do I kee
MinNum?

Thanks
Trevo

--
Tre_coo
-----------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...fo&userid=2641
View this thread: http://www.excelforum.com/showthread.php?threadid=47555

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Finding cell address for minimum number

See my earlier reply.

HTH,
Bernie
MS Excel MVP


"Tre_cool" wrote in message
...

I don't understand where I'd put in MinAddress(Range("V:V"))? Do I keep
MinNum?

Thanks
Trevor


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding cell address for minimum number


How do I call the function?? I tried MinAddress(rng), that didn't work.

Thank

--
Tre_coo
-----------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...fo&userid=2641
View this thread: http://www.excelforum.com/showthread.php?threadid=47555

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Finding cell address for minimum number

As defined below, used like this from the worksheet

=MinAddress(V:V)
=MinAddress(A1:A100)
=MinAddress(rng)
The use immediately above only works if you have a range named "rng" on the
worksheet (Set up through Insert Names etc...)

Or use it like this from a macro

Dim myAdd As String
myAdd = MinAddress(Range("V:V"))
MsgBox myAdd

Or, if you have a defined range variable named rng:

Dim myAdd As String
Dim rng As Range
Set rng = Range("A1:A100")
myAdd = MinAddress(rng)
MsgBox myAdd

HTH,
Bernie
MS Excel MVP


Function MinAddress(rng As Range) As String
MinAddress = rng(Application.Match( _
Application.Min(rng), rng, False)).Address
End Function


"Tre_cool" wrote in
message ...

How do I call the function?? I tried MinAddress(rng), that didn't work.

Thanks


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile:
http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding cell address for minimum number


Bernie, I tried the following one. It worked for every number except 0.
If there was a 0 in the range, it didn't work. Please help. Thanks!

Dim myAdd As String
Dim rng As Range
Set rng = Range("A1:A100")
myAdd = MinAddress(rng)
MsgBox myAdd


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Finding cell address for minimum number

Tre,

Works for me. Try the test sub below.

HTH,
Bernie
MS Excel MVP

Sub test()
Dim myAdd As String
Dim rng As Range
Set rng = Range("A1:A100")
rng.ClearContents
rng.Value = 1
rng(3).Value = 0
myAdd = MinAddress(rng)
MsgBox "The zero value is in cell " & myAdd

End Sub
Function MinAddress(rng As Range) As String
MinAddress = rng(Application.Match( _
Application.Min(rng), rng, False)).Address
End Function



"Tre_cool" wrote in message
...

Bernie, I tried the following one. It worked for every number except 0.
If there was a 0 in the range, it didn't work. Please help. Thanks!

Dim myAdd As String
Dim rng As Range
Set rng = Range("A1:A100")
myAdd = MinAddress(rng)
MsgBox myAdd


--
Tre_cool
------------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...o&userid=26416
View this thread: http://www.excelforum.com/showthread...hreadid=475552



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding cell address for minimum number


Awesome!! Thanks a lot Bernie...worked perfectly!

--
Tre_coo
-----------------------------------------------------------------------
Tre_cool's Profile: http://www.excelforum.com/member.php...fo&userid=2641
View this thread: http://www.excelforum.com/showthread.php?threadid=47555

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
Finding Cell address by value default105 Excel Discussion (Misc queries) 2 June 30th 09 09:31 PM
Finding Minimum but if same number repeats in the range, then find MIK Excel Discussion (Misc queries) 1 January 9th 09 03:13 AM
Finding a minimum value in a cell that is constantly changing. Reid V Excel Worksheet Functions 1 June 20th 08 06:18 AM
Finding a minimum value and selecting the cell containing this val Kokomojo Excel Worksheet Functions 3 February 5th 06 09:33 PM
Finding the minimum in a selected number of rows of the same colum Mark Rugers Excel Worksheet Functions 5 July 20th 05 10:37 PM


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