Picking Next Highest Value

Robb0688

New Member
Joined
Aug 5, 2015
Messages
4
Hello,

I have a sheet I'm trying to build that will allow me to compare values in bands/tiers. The tiers aren't always consistent. Sometimes they count by 5s up through 250 and then 10s from there on, or count by 10s at the start, etc. I want the function to take the values I may input and find the next highest number in my established pricing tiers without going over and return the price associated with it. I'm having trouble writing a function that doesn't go over and that also handles exact matches ok. If I input 20 and I have pricing for 20, I don't want it to round up to 25 or 30.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hello Rob,

If the 5, 10, 15, .... are in column A - and you input your number in cell B1 - the following code will insert the next number higher or equivalent into cell C1

VBA Code:
Sub NextHighest()
Dim i As Integer
    For i = 1 To 24
    If Cells(i, 1).Value = Range("B1").Value Then
    Range("C1").Value = Cells(i + 1, 1).Value
    Exit Sub
    End If
    If Cells(i + 1, 1).Value > Range("B1").Value Then
    Range("C1").Value = Cells(i + 1, 1).Value
    Exit Sub
    End If
    Next i
End Sub


Jamie
 
Upvote 0
Solution
Hello Rob,

If the 5, 10, 15, .... are in column A - and you input your number in cell B1 - the following code will insert the next number higher or equivalent into cell C1

VBA Code:
Sub NextHighest()
Dim i As Integer
    For i = 1 To 24
    If Cells(i, 1).Value = Range("B1").Value Then
    Range("C1").Value = Cells(i + 1, 1).Value
    Exit Sub
    End If
    If Cells(i + 1, 1).Value > Range("B1").Value Then
    Range("C1").Value = Cells(i + 1, 1).Value
    Exit Sub
    End If
    Next i
End Sub


Jamie

Thank you, that worked!
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

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