check multiple conditions multiple times, excel VBA

grabrail

Board Regular
Joined
Sep 6, 2010
Messages
128
Office Version
  1. 365
Platform
  1. Windows
I have a form the has a number of sections, my users need to check a box for each section that needs to be checked. each section has 4 different options to be completed, that are mandatory.

The form has a submit button. One of the questions that has to be answered is OCRS score,

I have some code im trying to write, so when the submit button is pressed, it will check if the OCRS score has been filled in for any section that has been checked (Has a checkbox ticed)

The code I am trying to do is as follows

VBA Code:
If CheckBox1.Value = True And Me.OCRS_Score1.Value = "" Then
        MsgBox ("Please Enter OCRS Score")
    Else
    
     If CheckBox2.Value = True And Me.OCRS_Score2.Value = "" Then
        MsgBox ("Please Enter OCRS Score")
    Else
    
     If CheckBox3.Value = True And Me.OCRS_Score3.Value = "" Then
        MsgBox ("Please Enter OCRS Score")
    Else
    
     If CheckBox4.Value = True And Me.OCRS_Score4.Value = "" Then
        MsgBox ("Please Enter OCRS Score")
    Else
        
    tyres.Hide
    End If

This works if I just use the first check, i.e. checkbox 1 and tyres.hide is after the first else, however when the code is as above, I just get an error, "Block If without End If"

I get what this means, that my If statements dont have enough end ifs, but I'm not even sure if I am writing this the corerct way
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Managed to fix this with the following code

VBA Code:
If (Me.CheckBox1.Value = True And Me.OCRS_Score1.Value = "") Or (Me.CheckBox2.Value = True And Me.OCRS_Score2.Value = "") Or (Me.CheckBox3.Value = True And Me.OCRS_Score3.Value = "") Or (Me.CheckBox4.Value = True And Me.OCRS_Score4.Value = "") Then
        MsgBox ("Please Enter OCRS Score")
   
    Else
        
    tyres.Hide
    End If
 
Upvote 0
Solution

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top