Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As a user, I would soon learn to dislike a system with so many input boxes.
That's why I showed the technique with highlighting of the textboxes and construction of a single message box. YMMV - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "Hannah Lu" wrote in message ... Thank all of you so much for your replies! I ended up taking elements from all of your suggestions, and came up with some code that is SO MUCH SIMPLER than what I had before, and I actually know what all of it means :) Again, thanks for your help, and my revised code is below -Hannah ----Revised Code---- Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Application.ScreenUpdating = False If Worksheets("human health csm").Visible = True Then Worksheets("human health csm").Select End If Do Until Range("az6").Value = 5 With Worksheets("human health csm") If .SurfaceCheck6.Value = True And Len(.SurfaceSoilTextbox.Text) = 0 Then 'needs input; add to message .SurfaceSoilTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Surface Soil section.", "Please enter a transport mechanism.") Range("az1").Value = 1 If .SurfaceSoilTextbox.Value = "FALSE" Then .SurfaceSoilTextbox.Value = "" Range("az1").Value = 0 End If Else 'input provided or not needed Range("az1").Value = 1 End If If .SubSurfaceCheck3.Value = True And Len(.SubsurfaceSoilTextbox.Text) = 0 Then 'needs input; add to message .SubsurfaceSoilTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Subsurface Soil section." & vbNewLine, "Please enter a transport mechanism.") Range("az2").Value = 1 If .SubsurfaceSoilTextbox.Value = "FALSE" Then .SubsurfaceSoilTextbox.Value = "" Range("az2").Value = 0 End If Else 'input provided or not needed Range("az2").Value = 1 End If If .GroundwaterCheck5.Value = True And Len(.GroundwaterTextbox.Text) = 0 Then 'needs input; add to message .GroundwaterTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Groundwater section." & vbNewLine, "Please enter a transport mechanism.") Range("az3").Value = 1 If .GroundwaterTextbox.Value = "FALSE" Then .GroundwaterTextbox.Value = "" Range("az3").Value = 0 End If Else 'input provided or not needed Range("az3").Value = 1 End If If .SurfaceWaterCheck4.Value = True And Len(.SurfaceWaterTextbox.Text) = 0 Then 'needs input; add to message .SurfaceWaterTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Surface Water section." & vbNewLine, "Please enter a transport mechanism.") Range("az4").Value = 1 If .SurfaceWaterTextbox.Value = "FALSE" Then .SurfaceWaterTextbox.Value = "" Range("az4").Value = 0 End If Else 'input provided or not needed Range("az4").Value = 1 End If If .SedimentCheck3.Value = True And Len(.SedimentTextbox.Text) = 0 Then 'needs input; add to message .SedimentTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Sediment Water section." & vbNewLine, "Please enter a transport mechanism.") Range("az5").Value = 1 If .SedimentTextbox.Value = "FALSE" Then .SedimentTextbox.Value = "" Range("az5").Value = 0 End If Else 'input provided or not needed Range("az5").Value = 1 End If End With Loop Range("az1:az5").ClearContents Application.ScreenUpdating = True End Sub ----End---- "Hannah Lu" wrote: Hi, I have a worksheet with five checkboxes and text boxes. If a checkbox is checked, data should be entered in the corresponding text box. I'd like an input box (or some other form of validation - open to suggestions) to pop up if the checkbox is checked and the text box is empty. I figured the easiest way is to put the code in the Thisworkbook module, beforesave, and I can get it to work using multiple nested If statements, but there has to be an easier way! Otherwise I'll end up with a mile of code that's hard to navigate. Is there some loop I could use? A sample of the code I'm working with now is below, thank you so much for your help! Check boxes and corresponding text boxes a -SurfaceCheck6 and SurfaceSoilTextbox -SubSurfaceCheck3 and SubSurfaceSoilTextbox -GroundwaterCheck5 and GroundwaterTextbox -SurfaceWaterCheck4 and SurfaceWaterTextbox -SedimentCheck3 and SedimentTextbox If Worksheets("human health csm").Visible = True Then Worksheets("human health csm").Select With ActiveSheet 'Checks if the "Other" checkbox is checked/unchecked for Surface Soils If .SurfaceCheck6.Value = True And .SurfaceSoilTextbox.Text = "" Then 'value if true .SurfaceSoilTextbox.Activate .SurfaceSoilTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Surface Soil section.", "Please enter a transport mechanism.") If .SurfaceSoilTextbox.Value = "FALSE" Then .SurfaceSoilTextbox.Value = "" End If 'checks if the "Other" checkbox is checked/unchecked for Subsurface soils and cancels if necessary. If .SubSurfaceCheck3.Value = True And .SubsurfaceSoilTextbox.Text = "" Then .SubsurfaceSoilTextbox.Activate .SubsurfaceSoilTextbox.Value = Application.InputBox("Please enter a transport mechanism for the Subsurface Soil section.", "Please enter a transport mechanism.") If .SubsurfaceSoilTextbox.Value = "FALSE" Then .SubsurfaceSoilTextbox.Value = "" End If End If End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Nested IF statements | Excel Discussion (Misc queries) | |||
Nested If Statements | Excel Worksheet Functions | |||
Nested if statements | Excel Worksheet Functions | |||
Nested if statements | Excel Worksheet Functions | |||
Nested If statements | Excel Worksheet Functions |