How to populate ComboBoxes from ListBox selection? - excel

So I have a UserForm that has a ListBox and ComboBoxes.
I also have a button above the ListBox that when clicked, the data from the spreadsheet will be displayed.
If I clicked the value from the ListBox, it will be automatically displayed on the ComboBoxes below per column.
Say the value from the Schema column from the ListBox says "ABC", "ABC" will also be displayed on the ComboBox below it. It is the same with the other ComboBoxes.
Is there a possible way to do it?
I've been looking for answers but none of the methods have worked on me and I couldn't find any similar problems. Please help :(

You need to create a sub on Click event and then select one by one the columns
Private Sub <ListBox>_Click()
<ComboBox>.Value = <Userform>.<ListBox>.Column(0)
End Sub
Replace the < name > with the actual name of your objects
But as PEH said, I see no reason why this case would be a ComboBox, you may want to consider changing it for a TextBox

Related

How to run code when item is added to list box

I have built a userform where a customer can pick items from a list of articles (listbox 1) to add them to their shopping chart (listbox 2) by doubleclicking the item in listbox 1.
I want code to run each time an item is added to listbox 2.
This very simple examplewhich I tried on the "Change", "Enter" and "AfterUpdate" event works probably as designed, but not as I need it to:
Private Sub Basket_Change()
MsgBox "Change!"
End Sub
Nothing happens when an item is added, but when I manually select an item in listbox 2, the message appears.
I seem to recall that the change event is not triggered for textboxes when the change is not entered manually. This seems to be the same with listboxes.
I could write the line from listbox1 to a worksheet in the background at the same time I write it to listbox2, and start the code (some calculations that write values to other boxes in the same userform) from there, but I feel I should try a more direct alternative, if there is one, before I go that way.
Thanks for any hint in the right direction!

Updating a caption of a text box when something is changed in the userform

I have a userform that has a dropdown of choices and each choice has different information related to it. to make sure the user has selected the correct Item that they want I have created a sentence in the spreadsheet which updates with the relevant information. I would like this sentence to be displayed on the userform when anything is updated on the userform i.e. if a different item is selected from the dropdown, the caption of the textbox will also update.
is there a way of doing this? I am currently using the following but it seems to only update some of the time:
Private Sub Item_No_TB_Change()
Confirm_Info_Update.Caption = ThisWorkbook.Sheets("Email").Range("B60").Value
End Sub

Activex Combobox Not Selectable After Rows Unhidden

I have searched for a while now and dont see a solution to my issue. I have several activex comboboxes on a worksheet. For instant there are 5 Comboboxes in rows 1-5. The user clicks a button that is linked to a userform which will hide or unhide the 5 rows based on the users input. Hidding the 5 rows is not issue using vba. The problem that I am facing is when the 5 rows are unhidden, the comboboxes are non-selectable. What i mean is the user cant select or begin typing anything into them. They are visible but almost like an invisible object is over them so a user cannot select them.
Making a copy of the worksheet or selecting "design mode" and moving the boxes slightly, the comboboxes are selectable again. I dont want to keep copying sheets and I haven't found a way to move the comboboxes accurately outside of design-mode. Below is vba code I was trying to use to move the box but using -11 and 11 would just move the box up both times.
Anyone know why activex comboboxes get "locked" after they rows they are in become unhidden or have a solution?
ActiveSheet.Shapes("ComboBox1").IncrementTop 11
I had the exact same issue, using Excel 2019.
I don't know the cause, but I found a workable solution.
First, to also declare my specific problem:
I have a drop-down activex list, through which if "Option 1" is chosen, it hides many rows as well as ComboBox1 , but if "Option 2" is selected, then it shows these rows and the Combobox1.
So, when "Option 2" is called after "Option 1", the desired rows are visible, while ComboBox1 is visible but unselectable.
My solution is that I added a positional statement in the drop down list's code, in case of "Option 2" selected. As following:
ComboBox1.Top = 75 # or wherever you want it to be (trial&error)
ComboBox1.Left = 410 # or wherever you want it to be (trial&error)

Excel VBA ListBox (userform) - Multiple Selection Problem with fmMultiSelectSingle

I actually just created my own account here because I was not able to find an answer to the problem I currently have with Excel VBA..
I am creating a Userform with a ListBox, which is being populated via an multi-dimensional array. In certain cases, the ListBox is also repopulated after clicking on the ListBox, for example in a new row of that List (which automatically leads to a click-event).
Referring to the headline of my question, I discovered that when clicking on a new row of the list, both the previous and the selected row are underlined (i.e. "clicked", even though the MultiSelect option of the ListBox is set to "0-fmMultiSelectSingle"). If I request the .ListIndex Value, it just shows me the value of the previous row (not of the now new selected row).
The biggest problem though is the repopulation of the ListBox, which only (!)does not seem to work when clicking (and creating this multiselection) in a new row of the list.
I provided an example code of my situation. Naturally, my code is much more complex so I tried to shorten it up to the main aspects. I would love to send you guys a screenshot of my userform, but the data is sensible (I hope you understand my problem anyways).
The Question: Is there a solution or sufficient workaround to populate the ListBox in a situation, where -by a Click-Event-, you choose a new row in the ListBox?
Thank you in advance for your kind help. I have been trying and searching for quite some time now; maybe somebody has faced a similar problem before!
-Graf_Rasen
Sub ListBox_Click()
intListIndex = Userform.ListBox.ListIndex
'When evaluating intListIndex in combination with clicking in a new row of 'the ListBox (which executes "Sub ListBox_Click"), intListIndex merely returns the value of the previously selected ListIndex
'defaults ListIndex, needs to be done for repopulation
Userform.ListBox.ListIndex = -1
'This does not work when changing into a new row in the ListBox
Userform.ListBox.List() = arr_DataListBox
'Redefines ListIndex
Userform.ListBox.ListIndex = intListIndex
End Sub
You cannot click in a "new" row in a listbox. It may look like you are selecting a new row, but really the event that fires is just the fact that you clicked the listbox. Hence the ListIndex value still shows the previous selection's index (which is actually still the current selection.

Can't use more than one combo box on excel

I have made two active X combo boxes for a list of 220 sites. Before making the active x combo box i have made a sheet that searches through my data and finds the sites that match with what i am typing as i go.
I then used the name manage, refering to the formula in the first cell of the list
=Sheet1!$G$2:INDEX(Sheet1!$G$2:$G$220,COUNTIF(Sheet1!$G$2:$G$220,"?*"))
I have then writen this in the ListFillRange in the properties of my combo box.
It works fine for one, but once i had made the second one and selected the site the first one will no longer let me search through.
I have used the same formulas on both but they originate from different sheets to see if this fixed the problem however that was unsuccessful. (the boxes are on different sheets) When i click on the next sheet after using the box on the first sheet, it still shows part of it as if it is crashing.
The boxes are independent so I'm not sure what to do next as i need to add another 3 on separate sheets.
I am also using this code for each box
Private Sub ComboBox1_Change()
ComboBox1.ListFillRange = "MList"
Me.ComboBox1.DropDown
End Sub
and similar for the other button but with a different range.
There is no need to use VBA for this, the Change Events specifically, if you just want to use and fill the combo boxes with Named Ranges.
The scenario I think you try to do is:
Create Named Ranges that will be the source of your combobox:
Fill the range with your data, select the range, Right Click, Select Define Name and give the range a name. MList in your case I believe.
Create Combobox:
Goto Developer Tab, Insert in your case ActiveX ComboBox, Draw it on your sheet, right click the ComboBox, select properties, find ListFillRange in properties and enter the name of the Named Range you created in step one
Repeat for Combobox 2, with the same or a different Named Range depending on what you try to do
Leave Design Mode
Boths Comboboxes can now be used to type in what you are looking for.
If this is not what you tried to do, please try edit your question and in detail try to explain what you try to do and what you like to accomplish by doing so.

Resources