Confused on a code??

Joshua AA

New Member
Joined
Feb 5, 2013
Messages
2
Hi everyone I'm Josh new here I'm designing a quotation sheet that has to have validation so incorrect data cannot be inputted, this is going to be long-winded but stay with me.

I'm trying to create a code in vba that checks 2 cells and clears one if they both don't meet certain requirements let me explain:
I need a code that will look into lets say Cell 'A1' and Cell 'B3', and if cell A1 equals 2 and cell B3 is greater and equals 50 so it is 50 and higher, then B3 will be cleared.

The scenario is basically this: you can choose 5 rooms 1,2,3,4,5 and in those rooms you can only fit a certain amount of people say 15 in room 1, 60 in room 2 and so on, so I'm trying to make sure that if a cell is displaying room 3 then the amount of people cannot go over 50 or if it does then the cell is cleared
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
maybe this is what you need?

Code:
Sub test()
'[CellA1] This is a named range that i have called CellA1 so you know what cell i am referring too
'Same for [CellB3]


'Open a case select
Select Case [CellA1] 'this is the cell that returns the number of rooms chosen


Case 1 'After the word case is the variable that can be in [CellA1]


'If it is this case then put the code you want to run below...
If [CellB3] >= 15 Then
[CellB3] = ""
End If


Case 2
If [CellB3] >= 60 Then
[CellB3] = ""
MsgBox "Sorry, the max number of people allowed is capped at 59" 'maybe throw in a message to say why its being zeroed?
End If


Case 3
If [CellB3] >= 50 Then
[CellB3] = ""
End If


Case 4
'code
Case 5
'more code


'Close the select case
End Select


'finish macro
End Sub
 
Upvote 0
Thanks a bunch yeah it worked i think i was messing up the placement for the equals and greater signs yeah but that is the code thanks again
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,926
Members
449,479
Latest member
nana abanyin

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