+ Reply to Thread
Results 1 to 2 of 2

Issue Check Box validation, once check box must be ticked in range

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    5

    Issue Check Box validation, once check box must be ticked in range

    Hi, I have a sheet with 26 active x checkboxes, I am wanting to incorporate some validation so one of the checkboxes must be ticked before an action can be completed. So far I have had some great help from this forum to send me on my way, and need this part to complete my sheet. In this case it is something very simple I am missing!

    The code below checks which checkboxes are checked and depening on which will email to a particular email address. I have tried introducing a case whereby if none of the checkboxes are ticked a message will be displayed. I have been looking at this for so long now I just cant get my else clause working.

    'Validation to choose which email route, validate checkboxes in range LA
    
    T1 = True
    T2 = True
    T1 = False
    T2 = False
    
    
                For Each OleObj In Worksheets("SAP Access Request Form").OLEObjects
                    If TypeName(OleObj.Object) = "CheckBox" Then
    
                Select Case OleObj.Name
                
                Case "CheckBox1" To "CheckBox10", "CheckBox22" To "CheckBox26"
                T1 = T1 Or OleObj.Object.Value
                               
                Case "CheckBox11" To "CheckBox21"
                T2 = T2 Or OleObj.Object.Value
                
                
                End Select
                       
                    End If
                
                     Next OleObj
            
                If (Not T1) And (Not T2) Then MsgBox ("tick one")
                
                Cancel = True
            
            Exit Sub
            Else
            
                If T1 = True Then AuthEmailAddress = "@email.co.uk"
                If T2 = True Then AuthEmailAddress = "wmaill@.com"
                If T1 = True Then Approver = " me,"
                If T2 = True Then Approver = " you,"
    
    End If

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Issue Check Box validation, once check box must be ticked in range

    Take the msgbox off the If statement line
    If (Not t1) And (Not t2) Then
      MsgBox ("tick one")
                
                Cancel = True
            
            Exit Sub
            Else
    'etc etc
    Avoid using If then DO SOMETHING
    instead
    If then
    DO SOMETHING
    Else
    Do Some other job
    End If
    For example you last section of code
    If T1 = True Then
    AuthEmailAddress = "@email.co.uk"
    Approver = " me,"
    End If
    If T2 = True Then
    AuthEmailAddress = "wmaill@.com"
    Approver = " you,"
    End If
    Avoid completing an If Then on one line - it is not good programming practice (IMO)
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1