jonsharman
New Member
- Joined
- Jan 4, 2014
- Messages
- 28
Hi,
I currently have a workbook that is used to derive the value of a vehicle based on a certain set of criteria. It was planned that the cells on the workbook would be updated by the user on the basis that only the cells that required an input were unlocked for editing and that where a certain input was required (for example year of manufacture, plate of car etc) this was set up using data validation and named lists (=YEAR, =PLATE, =VARIABLE and so on). I then added a TAB order macro to the workbook so the user always started of a cell E2 and on pressing of the TAB key took them to the next cell they needed to input information into.
It has since come to pass that some users still struggle to fill out all the required fields and get confused when they input the wrong information into a cell causing the calculation to fail. I have decided to create a UserForm to help with data entry and therefore if a user wants to use the 'easy' mode they click a button on the workbook and the UserForm opens and prompts them for data input. Once they submit the form it copies the entered data to the correct cells on the worksheet and the caculation occurs.
Using the UserForm I have set up some text boxes as free entry, some requiring the input from a list box with and some that are limited to a certain number of digits or characters. However this is about where my Excel knowledge falls away!
If the user does not fill in a mandatory field or indeed types a value into a list box that is not in the predefined named ranges when the submit button is clicked Excel generates an error and goes back to the workbook and thus the calculation fails. What I would like to do is that when the Submit button is pressed the macro checks that all mandatory fields are filled in and in the allowable range; if something is missing it prompts the user to go back to the UserForm and either fill it in or correct the incorrect information.
Can anyone offer any guidance on how to do this? Below is the code for the UserForm I am using and I have attached a screen shot of the form so hopefully it makes a bit more sense!
Many many thanks in advance ...
Jon
I currently have a workbook that is used to derive the value of a vehicle based on a certain set of criteria. It was planned that the cells on the workbook would be updated by the user on the basis that only the cells that required an input were unlocked for editing and that where a certain input was required (for example year of manufacture, plate of car etc) this was set up using data validation and named lists (=YEAR, =PLATE, =VARIABLE and so on). I then added a TAB order macro to the workbook so the user always started of a cell E2 and on pressing of the TAB key took them to the next cell they needed to input information into.
It has since come to pass that some users still struggle to fill out all the required fields and get confused when they input the wrong information into a cell causing the calculation to fail. I have decided to create a UserForm to help with data entry and therefore if a user wants to use the 'easy' mode they click a button on the workbook and the UserForm opens and prompts them for data input. Once they submit the form it copies the entered data to the correct cells on the worksheet and the caculation occurs.
Using the UserForm I have set up some text boxes as free entry, some requiring the input from a list box with and some that are limited to a certain number of digits or characters. However this is about where my Excel knowledge falls away!
If the user does not fill in a mandatory field or indeed types a value into a list box that is not in the predefined named ranges when the submit button is clicked Excel generates an error and goes back to the workbook and thus the calculation fails. What I would like to do is that when the Submit button is pressed the macro checks that all mandatory fields are filled in and in the allowable range; if something is missing it prompts the user to go back to the UserForm and either fill it in or correct the incorrect information.
Can anyone offer any guidance on how to do this? Below is the code for the UserForm I am using and I have attached a screen shot of the form so hopefully it makes a bit more sense!
Many many thanks in advance ...
Jon
Code:
Private Sub SubmitButton_Click()
Dim CD As String 'Free Text Value (MANDATORY)
Dim CPr As Currency 'Price Without £ Marker EG 7995 (No Text Allowed) (MANDATORY)
Dim CMo As String 'Free Text Value (MANDATORY)
Dim CY As Long 'List Box Entry (Name Defined In Workbook As =YEAR) (MANDATORY)
Dim CPl As String 'List Box Entry (Name Defined In Workbook As =PLATE) (MANDATORY)
Dim CMi As Long 'Number Entry With No Decimal Points EG '39542' (MANDATORY)
Dim CS As String 'Free Text Entry (MANDATORY)
Dim CMA As Currency 'List Box Entry (Name Defined In Wookbook As =VARIABLE) (OPTIONAL)
Dim CCA As Currency 'List Box Entry (Name Defined In Wookbook As =VARIABLE) (OPTIONAL)
Dim CSA As Currency 'List Box Entry (Name Defined In Wookbook As =VARIABLE) (OPTIONAL)
Dim OY As Long 'List Box Entry (Name Defined In Workbook As =YEAR) (MANDATORY)
Dim OPl As String 'List Box Entry (Name Defined In Wookbook As =PLATE) (MANDATORY)
Dim OMi As Long 'Number Entry With No Decimal Points EG '39542' (MANDATORY)
Dim OS As String 'Free Text Entry (MANDATORY)
Dim STK As String 'Stock Number Entry That Must Being With A 'U' And No More Than 6 Digits Long EG 'U12345' (OPTIONAL)
Dim REG As String 'Free Text Entry For Max 9 Characters EG 'NU61 REG' (OPTIONAL)
'Copy VehicleInput User Form Data To DIM
CD = CompDealer.Value
CPr = CompPrice.Value
CMo = CompVehicle.Value
CY = CompYear.Value
CPl = CompPlate.Value
CMi = CompMiles.Value
CS = CompSpec.Value
CMA = CompModelAdjust.Value
CCA = CompColourAdjust.Value
CSA = CompSpecAdjust.Value
OY = OurYear.Value
OPl = OurPlate.Value
OMi = OurMiles.Value
OS = OurSpec.Value
STK = StockNumber.Value
REG = RegNumber.Value
'Write Data To UCM Pricing Sheet
Application.ScreenUpdating = False
Sheets("UCMPRICING").Range("C13") = CD
Sheets("UCMPRICING").Range("C15") = CPr
Sheets("UCMPRICING").Range("C17") = CMo
Sheets("UCMPRICING").Range("C19") = CY
Sheets("UCMPRICING").Range("C21") = CPl
Sheets("UCMPRICING").Range("C23") = CMi
Sheets("UCMPRICING").Range("C25") = CS
Sheets("UCMPRICING").Range("C43") = CMA
Sheets("UCMPRICING").Range("C51") = CCA
Sheets("UCMPRICING").Range("C53") = CSA
Sheets("UCMPRICING").Range("J19") = OY
Sheets("UCMPRICING").Range("J21") = OPl
Sheets("UCMPRICING").Range("J23") = OMi
Sheets("UCMPRICING").Range("J25") = OS
'Return To UCM Pricing Workbook
Unload Me
End Sub
Private Sub Cancel_Click()
'Cancel VehicleInput User Form & Maximise Window
Application.WindowState = xlMaximized
Unload Me
End Sub
Private Sub ClearButton_Click()
'Reset VehicleInput User Form
Call UserForm_Activate
End Sub
Private Sub UserForm_Activate()
'Clear VehicleInput User Form Ready For Input
CompDealer.Value = ""
CompPrice.Value = ""
CompVehicle.Value = ""
CompYear.Value = ""
CompPlate.Value = ""
CompMiles.Value = ""
CompSpec.Value = ""
CompModelAdjust.Value = ""
CompColourAdjust.Value = ""
CompSpecAdjust.Value = ""
OurYear.Value = ""
OurPlate.Value = ""
OurMiles.Value = ""
OurSpec.Value = ""
StockNumber.Value = ""
RegNumber.Value = ""
'Clear UCM Pricing Sheet Boxes Ready To Accept Input
Application.ScreenUpdating = False
Sheets("UCMPRICING").Activate
Range("C13").Select
Selection.ClearContents
Range("C15").Select
Selection.ClearContents
Range("C17").Select
Selection.ClearContents
Range("C19").Select
Selection.ClearContents
Range("C21").Select
Selection.ClearContents
Range("C23").Select
Selection.ClearContents
Range("C25").Select
Selection.ClearContents
Range("J19").Select
Selection.ClearContents
Range("J21").Select
Selection.ClearContents
Range("J23").Select
Selection.ClearContents
Range("J25").Select
Selection.ClearContents
Range("C43").Select
Selection.ClearContents
Range("C51").Select
Selection.ClearContents
Range("C53").Select
Selection.ClearContents
Range("K2").Select
Selection.ClearContents
'Return User To Starting Point
Range("E2").Select
Selection.ClearContents
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
'Minimize Excel On VehicleInput User Form Run
Application.WindowState = xlMinimized
End Sub