If Then statement not working

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
144
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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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.
 
Upvote 0
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...
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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