View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Hannah Lu Hannah Lu is offline
external usenet poster
 
Posts: 1
Default Simpler way for nested If statements (VBA)

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