Limit cell value based on a drop down list

little jimmy

New Member
Joined
Mar 21, 2013
Messages
13
Hi,

I am trying to redesign an expenses form for work and need to put certain limits on meal types.

You can claim for breakfast, lunch and dinner and the maximum amount you can claim is £5, £5 and £18 respectively. The meal options are selected from a drop down list (there are other items in the list such as taxi, car park, bus etc..but these do not have limits to their value).

If someone wants to claim for breakfast they will choose that from the drop down list but if they enter a value greater than £5 I want a warning message to pop up (just like data validation) saying something like "breakfast amount exceeded" or "dinner amount exceeded" and will not allow them to enter more than £5. Likewise with lunch £5 and Dinner £18, but if they choose taxi or bus or other option from the drop down the value is not restricted.

Hope this makes sense.
 

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
In which cell is the drop down list and in which cell do they enter the dinner amount?
 
Upvote 0
I have used the HTML maker and posted the code below. I'm not sure how this code stuff works so I will try to describe the layout (just in case).
The expense type is in column B and the data validation list is kept in column I. You will click in cell b2 and choose an option from the drop down list (say breakfast) then you will type the amount in column C so in C2 you will put £3.50. If you put £6 (or anything over £5) you will get an error message and it will stop you from entering anything over £5.
The problem is they could choose any item from the drop down list and the limit can be £5, £18 or any value. Then you choose your next expense in cell B3, B4,B5 etc...

Thanks



Cell Formulas
RangeFormula
A1Date
A243160
A343160
A443160
A543161
A643161
B1expense type
B2breakfast
B3lunch
B4dinner
B5breakfast
B6lunch
B7dinner
B8taxi
B9car park
C1amount
C22.5
C34.99
C412.99
C55.5
C64.99
C718
C835
C922
I1Data validation
I3breakfast
I4lunch
I5dinner
I6taxi
I7bus
I8car park
I9misc
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in column B and then enter a number in column C and exit the cell.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
    Select Case Target.Offset(0, -1).Value
        Case "breakfast", "lunch"
            If Target > 5 Then
                Target.ClearContents
                MsgBox Target.Offset(0, -1) & " amount exceeded.  Please enter a maximum of 5."
                Target.Select
            End If
        Case "dinner"
            If Target > 18 Then
                Target.ClearContents
                MsgBox Target.Offset(0, -1) & " amount exceeded.  Please enter a maximum of 18."
                Target.Select
            End If
    End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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