UserForm ListBox Change not Updating TextBox Visibility - excel

I have a UserForm that has a ListBox named EIDLList and after that there's a TextBox EIDLAmountLabel and EIDLAmountText. I've written a snippet of code that is supposed to grey out both TextBoxes if the ListBox selection is set to "No" but for some reason it's not working. I've tried about 10 different variations using Case, If, UCase, etc and none work. I appreciate any input.
Private Sub EIDLList_Change()
If EIDLList.Value = "No" Then
EIDLAmountLabel.Enabled = False
EIDLAmountText.Enabled = False
Else
EIDLAmountLabel.Enabled = True
EIDLAmountText.Enabled = True
End If
End Sub

I changed the fields from ListBox to ComboBox and now the code works perfectly. Not sure how or why that matters.

Related

Userform Excel Checkbox Code Not executing

Hi I am trying to get the following Macro to work when the checkbox on the userform is not selected. The macro works fine when the checkbox is selected. But when I unselect the checkbox it does not change the value of "E38" to ""
I am also looking for a way for the Checkbox to remain selected once I unload the userform
Private Sub CheckBox_AddBDetails_Click()
If CheckBox_AddBDetails = True Then
Worksheets("Schedule of Supports").Range("E38").Value = TextBox_Name.Value
Else
Worksheets("Schedule of Supports").Range("E38").Value = ""
End If
End Sub

vba both checkbox trigger and dropdown triggers does work together

i have an excel file like the following:
[enter image description here]enter image description here
[1]: https://i.stack.imgur.com/QVe6i.png
this checkbox is being controlled by a trigger and the code is as follows:
Sub CheckBox1_Click()
If Range("CheckBox1").Value = True Then
Range("ET").Rows.Hidden = True
Else:
Range("ET").Rows.Hidden = False
End If
If Range("CheckBox1").Value = True And Range("CheckBox1a").Value = True Then
Range("A50:A53").Rows.Hidden = False
Range("A61:A63").Rows.Hidden = False
Else:
Range("A50:A53").Rows.Hidden = True
Range("A61:A63").Rows.Hidden = True
End If
End sub
if the value of the checkbox is true, it hides rows "A50:A53" and"A61:A63" and unhides when the value is False. works perfect!
On the Same sheet, i have a dropdown that does the same stuff based on the selected option: following is the excel file:
[1]: https://i.stack.imgur.com/EvCt0.png
The same as the CheckBox, the dropdown option also, hides rows "A209:A210", if yes is selected. the triggers for the dropdown is as follows:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
' Section 4. Testing part 1
If Target.Column = 53 And Target.row = 208 Then
If Target.Value = "Yes" Then
Range("Addition").Rows.Hidden = False
Range("A112:A113").Rows.Hidden = True
ElseIf Target.Value = "No" Then
Range("A112:A113").Rows.Hidden = False
Range("Addition").Rows.Hidden = True
End If
End If
End sub
The issue now is. When i start to work with the CheckBoxes, they work fine however the Dropdown doesn't respond and the same thing happens if the start to work with the dropdown, the checkboxes stop to respond.
Any suggestion or help is highly appreciated!
Instead of CheckBox1_Click try the CheckBox1_Change event. This will ensure the checkbox is updating every time the value changes, even if if doesn't gain or lose focus.
Other than that, you will need to have something in Workbook_Open that checks the default status of those checkboxes and ranges, hiding and showing rows as necessary.
You will also need a separate event just for CheckBox1a. Each CheckBox_Change script only triggers based on the named object in the script's title. For example CheckBox1_Change will only trigger for changes to a matching CheckBox1 object. So if you want things to happen when the user clicks on CheckBox1a then you need a CheckBox1a_Change script.
Finally, you are retrieving and comparing checkbox values using Range("CheckBox1") which is not intended. There is a built in method for accessing these objects through VBA. Each CheckBox is added to the Worksheet object as a member. In the sheet's code module you can write Me.CheckBox1.Value. In an external code module you could write Sheets("Sheet1").CheckBox1.Value.

Disable/Enable Tabstrip on Multitab based on Checkbox value- EXCEL

I have a userform with a multitab containing 8 tabs. I require a user to use checkboxes on tab 6. I'm try to disable the user from selecting the next tab (tab 7) if Checkbox 1 and Checkbox 2 are left unchecked. They should only be able to access the next tab if they select one of the two checkboxes.
Private Sub MultiPage1_Change()
If Failed1.Value = False Or Passed1.Value = False Then
Me.MultiPage1.Pages(7).Enabled = False
Exit Sub
ElseIf Failed1.Value = True Or Passed1.Value = True Then
Me.MultiPage1.Pages(7).Enabled = True
End If
End Sub
I can't quite get the code to work the way I want it to. Any help would be greatly appreciated.
FYI - I'm a VBA n00b.
Me.MultiPageName.Pages(index).enabled = false
Me = the form active where multipage is present
MulitipageName = named multipage
Index = place of the page to enable copied from:http://www.excelforum.com/excel-programming-vba-macros/534056-is-it-possible-to-disable-a-tab-page-on-a-multipage-userform.html

Hide or disable a button if the sheet is protected

For my form I need to hide or disable a textbox with a on-click delete macro attached to it when the sheet is protected. I'm talking about excel's build-in protection system. I've looked at several tutorials but I can't seem to get it to work properly.
I tried multiple things including this:
If ActiveSheet.ProtectContents = True Then
TextBox1.Visible = False
Else
TextBox1.Visible = True
End If
Any idea how to do this?
Change
If ActiveSheet.ProtectContents = True Then
TextBox1.Visible = False
Else
TextBox1.Visible = True
End If
To
If ActiveSheet.ProtectContents = True Then
ActiveSheet.TextBox1.Visible = False
Else
ActiveSheet.TextBox1.Visible = True
End If
You are not declaring where the textbox is. This will fix it
It is not clear whether the textbox is embedded in the worksheet or in a userform.
If in the worksheet is it a text box based on a shape? These are created from the INSERT tab on the Ribbon.
Or is this an ActiveX textbox? These are created from the DEVELOPER tab on the Ribbon.
If on the other hand, you are referring to a textbox on a userform then you can use the following code (assuming the userform code name is UserForm1):
UserForm1.Controls("NameOfYourTextBox").Visible = Not ActiveSheet.ProtectContents

Assigning Excel VBA ActiveX ListBox .Selection to a TextBox

I'm trying to click a selection on an ActiveX ListBox and have value assigned to a TextBox then clear the ListBox. It seems straightforward but I'm
getting 'Object doesn't support this property or method' on the first line
This is what I'm using:
Private Sub ListBox1_Click()
ActiveSheet.OLEObjects("TextBox3").Object.Value = ActiveSheet.OLEObjects("ListBox1").Object.Selection
ActiveSheet.OLEObjects("ListBox1").Object.Selection = ""
End Sub
Any thoughts on how to make this word or resources to search are appreciated.
Your code would be cleaner written like this:
Private Sub ListBox1_Click()
TextBox1.Value = ListBox1.Text
ListBox1.Selected(ListBox1.ListIndex) = False
End Sub
But there is a problem: the second line doesn't work inside the ListBox1_Change event (because it would create an infinite loop). I tried with Application.EnableEvents = False, but it didn't help.
I think you need to put the reset of the selection in another event, like the KeyUp or MouseUp.

Resources