If Then statement not working

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
123
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Getting Error "End If without If" I need text to fill text box only if no caller for comment is selected and not pull dropdown, and if not go ahead and pull dropdown.

VBA Code:
Private Sub Label1073_Click()

If Call_Form.Label1072.Caption = "Select Caller for Comment" Then
Call_Form.TextBox26.Value = "Select Caller for Comment First"

Else

Call_Form.ComboBox2.List = Sheets("Comments 2").Range("A2:A6").Value
ComboBox2.DropDown

End If

End Sub
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
11,942
Office Version
  1. 365
Platform
  1. Windows
Nothing stands out as being wrong with that code, is there some other code that could also be triggered at the point of the problem?

I notice that you haven't qualified the last line with the form name but I don't see that being the cause of the error that you're encountering.
 

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
123
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Nothing stands out as being wrong with that code, is there some other code that could also be triggered at the point of the problem?

I notice that you haven't qualified the last line with the form name but I don't see that being the cause of the error that you're encountering.


I ended up adding an exit sub before the else and it worked.... so... yea...
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
11,942
Office Version
  1. 365
Platform
  1. Windows
Best guess without seeing everything is that the line
VBA Code:
Call_Form.TextBox26.Value = "Select Caller for Comment First"
is triggering a TextBox26_Change procedure which could be the origin of the error, although I don't see why exiting would fix it.

Regardless of that, as I mentioned above, if there are errors in your posted code that I'm not seeing, there are none that would result in the error that you have encountered. Adding 'Exit Sub' might have fixed the problem for now, but I would expect it to reappear somewhere else later.
 

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
123
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Best guess without seeing everything is that the line
VBA Code:
Call_Form.TextBox26.Value = "Select Caller for Comment First"
is triggering a TextBox26_Change procedure which could be the origin of the error, although I don't see why exiting would fix it.

Regardless of that, as I mentioned above, if there are errors in your posted code that I'm not seeing, there are none that would result in the error that you have encountered. Adding 'Exit Sub' might have fixed the problem for now, but I would expect it to reappear somewhere else later.


Code that Works!

VBA Code:
Private Sub Label1073_Click()
If Call_Form.Label1072.Caption = "Select Caller for Comment" Then
Call_Form.TextBox26.Value = "Select Caller for Comment First"

Exit Sub
Else

Call_Form.ComboBox2.List = Sheets("Comments 2").Range("A2:A6").Value
ComboBox2.DropDown
End If

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,553
Messages
5,596,806
Members
414,103
Latest member
imamalidadashzada

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
Top