VBA - Smallest number in range (greater than -1)

Beachson

Active Member
Joined
Oct 28, 2009
Messages
468
How would I state the following in VBA? ...

Code:
If ActiveCell.Offset(0, 1) > -1 AND _
   ActiveCell.Offset(0, 2) > -1 Then

   ActiveCell.Offset(1, 0)

Else

Below is my question on how to state in VBA. Would go right after "Else" in the above code" ...

Smallest number (must be greater than -1) in the range of ActiveCell.Offset(0, 2):ActiveCell.Offset(0, 5)

Thanks for any help everyone
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I can't tell what you're trying to do; maybe this:

Code:
MsgBox Evaluate(Replace("=min(if(@ > -1, @))", "@", ActiveCell.Resize(5).Address))
 
Upvote 0
Smallest number (must be greater than -1) in the range of ActiveCell.Offset(0, 2):ActiveCell.Offset(0, 5)

Maybe...
Code:
Dim SmallestNumber As Double

SmallestNumber = Evaluate(Replace("=MIN(IF(@>-1,@))", "@", ActiveCell.Offset(, 2).Resize(, 4).Address))
MsgBox SmallestNumber

M.
 
Upvote 0
Apologies, I wasn't clear.

Here is a repost that is clear ...

How would I state the following in VBA? ...

Code:
If ActiveCell.Offset(0, 1) > -1 AND _
   ActiveCell.Offset(0, 2) > -1 Then

   ActiveCell.Offset(1, 0)

Else

ActiveCell = [COLOR=#FF0000]Smallest number (greater than -1) within range ActiveCell.Offset(0, 2):ActiveCell.Offset(0, 5)[/COLOR]

Below is the part I need help with

ActiveCell = Smallest number (greater than -1) within range ActiveCell.Offset(0, 2):ActiveCell.Offset(0, 5)

Again, sorry for not being clear
 
Upvote 0
Apologies, I wasn't clear.

ActiveCell = Smallest number (greater than -1) within range ActiveCell.Offset(0, 2):ActiveCell.Offset(0, 5)


This?
Code:
Dim SmallestNumber As Double

SmallestNumber = Evaluate(Replace("=MIN(IF(@>-1,@))", "@", ActiveCell.Offset(, 2).Resize(, 4).Address))
Application.Goto ActiveCell.Offset(, 2).Resize(, 4).Find(SmallestNumber, lookat:=xlWhole, LookIn:=xlValues)

M.
 
Last edited:
Upvote 0
I was not very clear on this question and obviously asked it incorrectly. Sorry everyone ...

My desired result was achieved by the following (the question I had is in red) ...

Code:
If ActiveCell.Offset(0, 1) > -1 AND _
   ActiveCell.Offset(0, 2) > -1 Then

   ActiveCell.Offset(1, 0)

Else

[COLOR=#ff0000]Selection.FormulaArray = "=MIN(IF(RC[1]:RC[4]>-1,RC[1]:RC[4]))"

[/COLOR]End If
 
Last edited:
Upvote 0
More robust

Code:
Dim SmallestNumber As Double, rFound As Range

SmallestNumber = Evaluate(Replace("=MIN(IF(@>-1,@))", "@", ActiveCell.Offset(, 2).Resize(, 4).Address))
Set rFound = ActiveCell.Offset(, 2).Resize(, 4).Find(SmallestNumber, lookat:=xlWhole, LookIn:=xlValues)
If Not rFound Is Nothing Then Application.Goto rFound

M.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top