ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Visual Script to find smallest number greater than 0 (https://www.excelbanter.com/excel-discussion-misc-queries/247078-visual-script-find-smallest-number-greater-than-0-a.html)

Jeremy

Visual Script to find smallest number greater than 0
 
I am looking for a script to find the smallest number greater than 0 in a
column and select it.

Thank you

Mike H

Visual Script to find smallest number greater than 0
 
Hi,

Here's a brute force way

Sub ChangelinkT()
Dim MyMin As Long, LastRow As Long
Dim MyRange As Range
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & LastRow)
MyMin = WorksheetFunction.Max(MyRange)
For Each c In MyRange
If c.Value 0 And c.Value < MyMin Then
TheMin = c.Address
MyMin = c.Value
End If
Next
Range(TheMin).Select
End Sub

Mike

"Jeremy" wrote:

I am looking for a script to find the smallest number greater than 0 in a
column and select it.

Thank you


Jeremy

Visual Script to find smallest number greater than 0
 
Does this go under a Sub Macro?

Thanks

"Mike H" wrote:

Hi,

Here's a brute force way

Sub ChangelinkT()
Dim MyMin As Long, LastRow As Long
Dim MyRange As Range
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & LastRow)
MyMin = WorksheetFunction.Max(MyRange)
For Each c In MyRange
If c.Value 0 And c.Value < MyMin Then
TheMin = c.Address
MyMin = c.Value
End If
Next
Range(TheMin).Select
End Sub

Mike

"Jeremy" wrote:

I am looking for a script to find the smallest number greater than 0 in a
column and select it.

Thank you


Mike H

Visual Script to find smallest number greater than 0
 
Hi,

You can right click your sheet tab, view code and put it in there.

or better

You can open VB editor, right click 'ThisWorkbook' and insert module and put
it there and it will work on the active sheet i.e. the sheet that is visible.

Mike

"Jeremy" wrote:

Does this go under a Sub Macro?

Thanks

"Mike H" wrote:

Hi,

Here's a brute force way

Sub ChangelinkT()
Dim MyMin As Long, LastRow As Long
Dim MyRange As Range
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & LastRow)
MyMin = WorksheetFunction.Max(MyRange)
For Each c In MyRange
If c.Value 0 And c.Value < MyMin Then
TheMin = c.Address
MyMin = c.Value
End If
Next
Range(TheMin).Select
End Sub

Mike

"Jeremy" wrote:

I am looking for a script to find the smallest number greater than 0 in a
column and select it.

Thank you



All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com