Hello everyone
I have found a vba script to find the nearest value, but I need it to find the nearest value like round up
So value 1 would be to 1.5, 1.5 like 1.5, 2.6 would be 4 ect.
Right now, value 1 going to 0.75, but should be 1.5.
Hope some can fix it for me.
Merry Christmas.
I have found a vba script to find the nearest value, but I need it to find the nearest value like round up
VBA Code:
Sub Demo()
Dim numbers(), arrItem, maxItem, result, searchNum
searchNum = 0
numbers = Array(0.75, 1.5, 2.5, 4, 6, 10, 16, 25, 35, 50, 70, 95, 120, 150, 185, 240, 300)
maxItem = Application.Max(numbers)
For Each arrItem In numbers
If Abs(searchNum - arrItem) < maxItem Then
maxItem = Abs(searchNum - arrItem)
result = arrItem
End If
Next arrItem
Debug.Print result
End Sub
So value 1 would be to 1.5, 1.5 like 1.5, 2.6 would be 4 ect.
Right now, value 1 going to 0.75, but should be 1.5.
Hope some can fix it for me.
Merry Christmas.