I have a column with numbers and the word "Null" between these numbers. For a particular array, I want a code which puts in each row of that array the array's smallest number. E.g the column looks like this
Null
52
48.4
36.9
Null
Null
Null
Null
12
17
25.0
26.6
29.4
Null
Null
Null
And the result starts with "" because of the Null above followed by the smallest value of 36.9176 for the first array and then 12 for the last. The gaps represent the position of the "Null" word.
36.9
36.9
36.9
12
12
12
12
12
I have tried the codes but to no avail. Please anyone to help.
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Sub Smallest()
Dim rng As Range
Dim minimum As Double
Application.Volatile
Set rng = Intersect(rng.Parent.UsedRange, rng)
minimum = Application.WorksheetFunction.Min(rng)
Range = ("X9:X24")
MsgBox minimum
End Sub
OR
Function minimum(Rng As Range) As Double
Dim Cell As Range
Dim Cnt As Long
Dim Mina As Double
Application.Volatile
Set Rng = Intersect(Rng.Parent.UsedRange, Rng)
For Each Cell In Rng
If Cell.Value > 0 Then
Cnt = Cnt + 1
Mina = Cell.Value
Else
If Cell.Value < Mina Then
Mina = Cell.Value
Else
If Cell.Value = "Null" Then
Mina = ""
End If
Cnt = 0
minimum = Mina
End If
End If
Next
End Function
Bookmarks