I'm currently putting together a simple data reporting tool. Part of it is a UserForm for selecting parameters for applying filtering to the data. The UserForm has a ComboBox (loaded_cols_combo_box), three TextBoxes(cutoff_fraction_textbox, skip_n_textbox, max_range_sz_textbox), and two CommandButtons(confirm_settings_button, no_filter_button). As far as I can remember, I haven't made any recent alterations to the VBA for the UserForm and it was working as intended until very recently.
The issue is caused in two separate situations. When the X button in the upper-right is pressed it causes a Compile error with the message 'Only comments may appear after End Sub, End Function, or End Property'. And when the no_filter_button is pressed giving a compile error with the message 'Expected End Sub' and causing the application to get stuck with an inactive UserForm in the way so it can only be closed with task manager.
Oddly, adding an additional unmatched 'End Sub' before the final line of the no_filter_button_Click() sub fixes the issue with the no_filter_button so it functions as intended.
It's entirely possible I'm doing something really stupid/obvious here, but I've been staring at the VBA on and off since yesterday morning and can't work out what's wrong. Is there any way that code from other modules, etc could cause a compilation error in this UserForm? I would hope not.
The VBA for the UserForm is as follows:
The issue is caused in two separate situations. When the X button in the upper-right is pressed it causes a Compile error with the message 'Only comments may appear after End Sub, End Function, or End Property'. And when the no_filter_button is pressed giving a compile error with the message 'Expected End Sub' and causing the application to get stuck with an inactive UserForm in the way so it can only be closed with task manager.
Oddly, adding an additional unmatched 'End Sub' before the final line of the no_filter_button_Click() sub fixes the issue with the no_filter_button so it functions as intended.
It's entirely possible I'm doing something really stupid/obvious here, but I've been staring at the VBA on and off since yesterday morning and can't work out what's wrong. Is there any way that code from other modules, etc could cause a compilation error in this UserForm? I would hope not.
The VBA for the UserForm is as follows:
VBA Code:
Public valid_selection As Boolean
Public Function check_valid_inputs() As Boolean
Dim su_changed As Boolean: su_changed = False
If Application.ScreenUpdating Then
su_changed = True
Application.ScreenUpdating = False
End If
Dim valid_column As Boolean
valid_column = ("" <> loaded_cols_combo_box.Value)
Dim valid_cutoff As Boolean
Dim cutoff As Double
cutoff = CDbl(cutoff_fraction_textbox.Value)
valid_cutoff = (0 <= cutoff And cutoff <= 1)
Dim valid_skip_n As Boolean
Dim skip_n As Long
skip_n = CLng(skip_n_textbox.Value)
valid_skip_n = (skip_n > 0)
Dim valid_range_sz As Boolean
Dim range_sz As Long
range_sz = CLng(max_range_sz_textbox.Value)
valid_range_sz = (range_sz >= 0)
valid_selection = valid_column And _
valid_cutoff And _
valid_skip_n And _
valid_range_sz
check_valid_inputs = valid_selection
If su_changed Then
Application.ScreenUpdating = True
End If
End Function
Public Sub clear_inputs()
Dim su_changed As Boolean: su_changed = False
If Application.ScreenUpdating Then
su_changed = True
Application.ScreenUpdating = False
End If
' Clear selections
loaded_cols_combo_box.clear
cutoff_fraction_textbox.Value = ""
skip_n_textbox.Value = ""
max_range_sz_textbox.Value = ""
valid_selection = False
If su_changed Then
Application.ScreenUpdating = True
End If
End Sub
Private Sub confirm_settings_button_Click()
Dim su_changed As Boolean: su_changed = False
If Application.ScreenUpdating Then
su_changed = True
Application.ScreenUpdating = False
End If
If check_valid_inputs = True Then
FilterSelect.Hide
End If
If su_changed Then
Application.ScreenUpdating = True
End If
End Sub
Private Sub no_filter_button_Click()
Dim su_changed As Boolean: su_changed = False
If Application.ScreenUpdating Then
su_changed = True
Application.ScreenUpdating = False
End If
If loaded_cols_combo_box.ListCount <> 0 Then
loaded_cols_combo_box.Value = loaded_cols_combo_box.List(0)
Else
loaded_cols_combo_box.Value = "__NoFilter"
End If
cutoff_fraction_textbox.Value = 0
skip_n_textbox = 1
max_range_sz_textbox.Value = 1
valid_selection = True
FilterSelect.Hide
If su_changed Then
Application.ScreenUpdating = True
End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim su_changed As Boolean: su_changed = False
If Application.ScreenUpdating Then
su_changed = True
Application.ScreenUpdating = False
End If
' Clear form
clear_inputs
' Cancel loading
valid_selection = False
If su_changed Then
Application.ScreenUpdating = True
End If
End Sub