Value if between two criteria

Jennyb7714

Board Regular
Joined
Jan 29, 2008
Messages
78
I need to be able to assign a sale within a "bucket". Saying if 4500 falls within 5,000 and 50,000, then the result would be 4500 if it doesn't the result would be zero.
Can anyone help?
Appreciate it :)
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
sorry, I believe I have it.....if(and(G12>Q3,G12<Q2),G12,0) basically saying if it's greater than 5000 and less than 50000, then the value of the sale is returned (45000) if it's not between those two value's then it's zero...

Thanks so much for responding :)
 
Upvote 0
Do you want it in excel or vba?

Excel:

=IF(AND(SellAmount >=5000, SellAmount < 50000), SellAmount, 0)

VBA:

Public Sub Testing123()
Dim SellAmount#, DesiredOutput# '# is for double data types

SellAmount = 700

If SellAmount >= 500 And SellAmount < 50000 Then
DesiredOutput = SellAmount
Else
DesiredOutput = 0
End If

MsgBox DesiredOutput
End Sub

You could do a user-defined function too if you really wanted to get fancy.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,476
Members
452,915
Latest member
hannnahheileen

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