is it possible to write the value of a combobox to a cell but only when a user selects an item from the combobox but not if the userform refreshes and clears the combobox?
Szenario: I have a userform with 3 comboboxes. In these 3 comboboxes, the user chooses 3 items. Below these comboboxes, there is another combobox where the user can yet again chose an item, however, the given items are the previously selected items.
I solved the situation by using combobox.click and save it to the spreadsheet everytime it gets selected. However, if I now refresh the userform the cells get changed to empty and the cells get cleared out (as combobox.click gets triggered by that as well).
Anyone got an Idea?
Although this is mainly a theoretical question, I will be happy to provide any specific code. As my current code is over 2000 lines, it would be a bit much for SO.
Related
Good Evening All,
This is my first time using VBA, so apologies if this question seems pretty trivial.
I have a spreadsheet that lists out Document ref no, doc title, due dates, author etc - there's about 40 in total.
I have set up a "Search" Userform with CommandButtons on which are labels with the doc ref for each document.
I have then created another "Information" Userform with text boxes for all the pertinent information appending to the document. This Userform has a VLookup to go into the spreadsheet and pull all the information associated with a particular doc ref no.
Question: I would like to use the same Information Userform for all the document refs. I would therefore like the VLookup Value to equal the label name from whatever button is pressed on the initial search Userform. Is this possible?
I have managed to do this for one button, but trying to get it to work for multiple buttons baffles me.
For example if I haven't been clear. If I click on the button labelled Document 1 I want the form to drag all the info for document 1, and the same form to do the same thing if I click Document 2 and 3 and so on.
I would like the users of this file to copy a list of what we call "family codes" into a UserForm and then when they click a button on the UserForm, this list of family codes will populate a column in Excel. See below for exactly what I envision. Mostly, I just can't find a specific UserForm that can handle this, but I welcome any better ways to do this as well.
Example of "family codes": AS10, AS08, AS06, B137 -- These are always four digit letter/number combinations
Step 1:
User takes a list such as this that they want to use in the file:
AS10
AS08
AS06
They would copy these family codes vertically, as they are stored in separate rows in excel (ex. they would copy these families out of cells "A2:A4".
Step 2: The user pastes the vertical data into a UserForm
Step 3: The user clicks a command button on the userform and a macro pastes these families into cells "D2:D4" in vertical order in separate rows.
Wow I feel like an idiot... All I needed to do was change the "MultiLine" setting of the TextBox to true instead of false. Now I can paste in vertical data and pull it out.
Only hope is someone else with the same issue might discover my question before spending too much time!
I'm doing an userform where in one of the fields (lets say its combobox1) the user is asked for the number of failures, and for each failure he has to put the type of failure, number of part and in another field the type of rework (3 fields to fill for each failure). And what I would like to know if that if it's possible to generate comboboxes depending on the number of failures made. For example: if the user puts 3 in the field of failures, 9 comboboxes should appear and so on.
I also think that maybe another way would be to have the standards 3 comboboxes and clear the fields each time the user press a button and a counter appears indicating which failure description he is filling, but I would also like to know how this could integrate into the whole userform, which already has a "submit" button.
Maybe there could be another reasoning for this, and I would greatly appreciate any help.
I don't really have much experience using dynamically created tabstrips, but they may be helpful with creating the layout you're describing. I would recommended in the base userform, include a tabstrip with a single tab and the 3 comboboxes/textboxes that are needed for a single failure. (You could keep it invisible until after "combobox1" has a value, if desired) Then use the number from the combobox to dynamically create the additional tabs on the tabstrip:
Private Sub ComboBox_Change()
'To remove previous tabs if combobox changed
For i = 1 To TabStrip1.Tabs.Count - 1
TabStrip1.Tabs.Remove(i)
Next i
'Adding additional tabs to tabstrip
For i = 1 To ComboBox.Value - 1
TabStrip1.Tabs.Add
Next i
End Sub
The tab currently selected can be identified by using the TabStrip1.Value property. I think the change event is queued by the TabStrip1.Value changing.
You will have to manually clear out any values when the tab strip changes (or fill back in values they previously filled out but want to view again).
However, since you'd be determining which tab you're on by "index" (the .value property) you could create a 2d array (redim it to correct rows/columns based off combobox1's value) and use the tab "index" to store combobox values and retrieve existing values for when the user switches back to an existing tab.
And maybe consider "locking" the combobox1 so the value can't be changed by accident. This could be accomplished by having a variable initialized to, maybe -1, which gets set to the combobox value after they've started adding infor to the incidents. Or don't remove any tabstrip tabs, only add if the number is greater than the existing count. (If you want them to put in whatever value they'd like, maybe consider using a textbox?)
I'm trying to code a macro that uses a checkbox click to hide the row the checkbox is in. I've a task list of about 100 tasks and want to assign each row its own checkbox, so when the user clicks the box the row gets hidden from the remaining tasks.
The following video is a tutorial on how to accomplish hiding a row using a checkbox (you'll see your specific functionality at 4:10 in the tutorial video):
Creating a Checkbox to Hide and Unhide Rows in Excel
Rather than creating only one checkbox, you'll want to create one per row. So if you have 100 rows, you'll be creating 100 checkboxes.
Edit:
Playing around further, it seems that you can't assign a new array to a listbox via the .list=somelist approach when the assignment happens in response to a click on the listbox itself. Or rather, you can assign the list, but it simply won't visually populate the listbox...although Excel seems to think it's there.
The .additem or .removeitem methods do however result in a visual change when called from a listbox click, which means you have to build your new array up that way I guess. How tedious.
You can however feed a listbox an entirely new array using the .list=somelist approach via a CommandButton-initiated action. But the user has to obviously click a button to do this. Which in my case below defeats the purpose.
Edit Over.
I'm designing a UserForm to help filter PivotTables. It's a cross between the existing Pivot Filter functionality and a Slicer. Here's what you see if you double-click on a PivotField header:
Note the Search field at the top, and the three buttons immediately below that search field. If you type something into that field, then instead of displaying everything that's currently filtered, you instead get a list of any matches, and you can then apply those search results to the underlying PivotTable via those three CommandButtons. The first cb simply filters the PivotTable to reflect the search, and the other two let you add or remove any search result from an existing filter.
I want to do away with those three command buttons, and instead (in the event that a search is performed) simply list those three options at the top of the ListBox above any search results returned. Clicking on those three options will then trigger the exact same code as currently triggered by the Command Button.
Here's how that looks currently if I actually type something in that Search box (Note I haven't yet removed the three command buttons this does away with from that Search frame):
I've added a simple bit of code to the lbResults_Change() event handler that checks if a user clicks any of those first three options. All that code does is trigger the exact same routines as would be triggered if they'd simply clicked on the actual command buttons themselves:
For i = 0 To 4
If Me.lbResults.Selected(i) Then Exit For
Next i
Select Case i
Case 0: cmdApplySearch_Click
Case 1: cmdAddToFilter_Click
Case 2: cmdSubtractFromFilter_Click
Case 3: Me.lbResults.Selected(3) = False
End Select
Here' the problem: The listbox gets updated just fine if I click on those command buttons, as you can see from the below. The Pivot has been filtered accordingly, and those contextual search options have been removed from the top of the listbox (and the search field cleared):
But the listbox does NOT get updated if the exact same routine is triggered from a click on one of those top three options in listbox itself:
As you can see from the above screenshot, it still shows those three options at the top, even though they are NOT in the array that I assigned to the listbox, as evidenced by the screenshot below:
But as you could see from the earlier screenshot, it shows 7 items in the ListBox instead of the three there actually are. But there are indeed just three items that should be showing in that list box:
? .ListCount
3
? .List(0)
263213: ICT Systems Test Engineer
? .List(1)
263299: ICT Support and Test Engineers nec
? .List(2)
839313: Product Tester
Basically, as soon as I try to update what's in the listbox via a click on the listbox itself, I can't update it.
It doesn't seem to matter if I set focus to something other than the listbox before the filtering code executes, and I've even tried completely clearing the Listbox with .clear. It just doesn't clear, until I manually click on one of those command buttons again.
Anyone have any pointers?
Ah, what an idiot I am for overlooking the painfully obvious solution. The ListBox list happily redraws in response to any event other than the ListBox_Click event, right? So all I needed to do was to use the ListBox_Click event to determine what got clicked (as I currently do), and then use the ListBox_MouseUp event to trigger the actual updating of the ListBox list. Works a treat.
Hopefully this post will save someone else two days of pain in the future. Probably me.