LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested IF statements NancyB Excel Discussion (Misc queries) 3 May 5th 09 06:19 PM
Nested If Statements Sarah_Lecturer Excel Worksheet Functions 5 March 18th 09 02:53 AM
Nested if statements JBS Excel Worksheet Functions 2 March 6th 09 05:45 PM
Nested if statements JICDB Excel Worksheet Functions 2 November 20th 07 06:48 PM
Nested If statements [email protected] Excel Worksheet Functions 3 September 21st 06 10:13 PM


All times are GMT +1. The time now is 02:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"