Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
I have an excel template that I have set up to use as an order form. I need to be able to do the following:
1) one field is a drop down value list - I need the user to select one of the values - I found this thread and tried it - and it almost worked but I'm caught in a loop! I found this very helpful response to a similar question and tried it: Default Require specific cell entry before saving file Try this VBA event code (change the sheet name as appropriate): ------------------------------------------------------------------ Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 'If there is nothing in Sheet1 cell E59... If Len(ThisWorkbook.Sheets("Sheet1").Range("E59").Val ue) = 0 Then 'Notify the user and don't save the workbook. MsgBox "You must enter your name in cell E59 on Sheet1", , "ERROR" Cancel = True End If End Sub Paste this code into the ThisWorkbook module of the workbook where this validation should occur. From the Tools menu, select Macro Visual Basic Editor. This will open the Visual Basic Editor (VBE) for Excel. From the View menu in the VBE, select Project Explorer. It usually opens along the left side of the screen. You should see some bold text like "VBAProject (Book1)", where Book1 is the name of your workbook. Expand the indented list under it and one of the items listed should say ThisWorkbook. Double-click on ThisWorkbook and a new blank window should open to the right of the Project Explorer window. Paste the code above in that window. Close the VBE and save the file (you won't be able to unless there is something in E59). ------------------------------------------------------------------- This last sentence is "my loop"! I cannot save the code because there is nothing in the field but if I put something in the field to save the code it defeats the requirement (as the user could just leave what was in the field vs making a valid selection)............. ------------------------------------------------------------------- this is the actual code I used: Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 'If there is nothing in Sheet1 cell F18... If IsEmpty(Sheets("Sheet1").Range("F18")) Or _ Len(Sheets("Sheet1").Range("F18").Value) = 0 Then 'Notify the user and don't save the workbook. MsgBox "You must select a boot stripe color", , "ERROR" Cancel = True Exit Sub End If End Sub ---------------------------------------------------------------- 2) I need to also require users to select from a drop down list or type in a text box if a certain check box has been ticked (i.e. If you check "change hull color" then you must select which color from a list or type in a custom color in a text box 3) I need to require users to select from a drop down list if a check box is ticked (i.e. select seat X instead of seat Y - seat X requires the user to select a canvas color). much appreciate any help anyone can give me! Last edited by edentonmomster : September 6th 12 at 05:31 PM |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Require input in a cell before saving file | Excel Discussion (Misc queries) | |||
Require specific cell entry before saving file | Excel Discussion (Misc queries) | |||
Require specific cell entry before saving file | Excel Programming | |||
Require specific cell entry before saving file | Excel Programming | |||
Require specific cell entry before saving file | Excel Discussion (Misc queries) |