countif with doubles

brulet

New Member
Joined
May 6, 2011
Messages
20
Hey, I am trying to simply find the closest numbers to a value of type double, both largest and smallest in a range.

<code>
Function smallest(searchValue As Double, searchRange As Range, searchWorksheet As String)
Dim searchLocation, locatedValue As Variant
With Application.Worksheets(searchWorksheet)
searchLocation = Application.CountIf(searchRange, "<" & searchValue))
MsgBox searchValue
MsgBox searchRange.Address
MsgBox searchLocation
MsgBox ThisWorkbook.ActiveSheet.Name
searchRange.Select
If IsError(searchLocation) = False Then
locatedValue = Application.Small(searchRange, searchLocation)
If IsError(locatedValue) = False Then
smallest = locatedValue
Else
MsgBox "error 2"
End If
Else
MsgBox "error 1"
End If
End With
End Function

Sub testSmallest()
MsgBox smallest(0.5, Range("C1:C61"), "Site1.Frequency.1")
End Sub

</code>

It's returning zero, when the column has 60 values 0.0001 -> 1 which are also sorted.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Ahh, didn't realize ranges had parents associated with them and if they are set incorrectly...
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,676
Members
452,937
Latest member
Bhg1984

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