Getting Values from Multiple Comboxes in same sub - excel

I have an excel sheet workbook with 2 sheets. One sheet has data imported from an external source and the other sheet then filters this data. I want to be able to select a date range to narrow done the filtered results.
To do this, I have 4 comboboxes, one checkbox, and one button. When the button is clicked I want my sub to first see if the checkbox has been checked. If it has not, then just run filter the data regardless of date. If the checkbox is checked, I then want to look at the four comboboxes. The first two will have the start year and start month and the last two will have the end year and end month. I want to take these values and filter my data using this criteria as well when the checkbox has been checked.
The issue I am having is that I cannot get the value of the combobox. For example, I named one of my comboboxes "Start_Month". In my sub, when I select the sheet with the combobox first, then I use "Start_Month.Value" to check the combobox value, but this gives me runtime error 424 "Object Required".
Does anybody know how to get the value of four different comboboxes in the same sub or is this not possible?

Related

ComboBox values disappears

I have a sheet in excel with some comoboxes (I have three). The purpose of these are just for someone to be able to choose three different values (i.e. one value in every comobox) and then I have made some VBA code which retrieves some data and plots some graphs.
However, the problem is that I want the comoboxes to have a specific value every time someone either open the sheets or runs the daily update (the sheet is in a big excel file with multiple sheets which is updated on a daily basis). I have made the VBA in such a way that it remembers whatever you just pressed before, i.e. if you choose X in combobox1, Y in combobox2 and so on it remembers this. This is done by I first make a variable which I set to be equal to the value of ComboBox1, i.e. X = ComboBox1.Value and then just before the sub ends I set ComboBox1.Value = X. This works perfectly.
However, for some reason, I am not able to set some standard value for every combobox when opening the excel file for an example, i.e. by making a Workbooks_Open Sub in ThisWorkbook and manually setting the combobox values, i.e. ComboBox1.Value = "something". This is since if I go to the sheet where the the ComboBoxes are, and then afterwards go to another sheet, and then back to the combobox sheet, then the ComboBox values have disappeared.
This do not happen when I run the sub where the data is retrieved. Therefore, I thought I could just run some sub (when the excel file is updated) which manually sets the values of these combobox to something specific I choose. But again, when I go to another sheet and then back to the combobox sheet the combobox values have disappeared again. I don't understand why.
Any help to solve this is very much appreciated. Thanks.

Clear contents of hidden excel cells based on dropdown menu vba

I am looking to clear a set of cells (reset them) every time a new option is selected in the dropdown menu. However, based on the choice selected, a different combination of rows will be hidden. There are 12 of these dropdowns and so I need a function I can call that will clear only the cells related to that drop down (when all are unhidden there are 16 rows and 3 columns). I have tried using the formula below, however it does not recognize the hidden rows and ends up deleting the contents of the following dropdown's rows. Thank you in advance for your help.
Sub Clear(Target As Range)
Range(Target.Offset(16,).Address, Target.Offset(,3).Address).Value = " "
End Sub

unhide rows on sheet2 based on the values of checkboxes on sheet1

I have a workbook with three worksheets. On the first worksheet the user is asked to click "relevant" checkboxes that relate to their project. Based on these checkboxes one thing happens but on two worksheets:
On the first worksheet (same as checkboxes)
1. related rows appear when checked and disappear when not checked. This I have managed to figure out using the following code for each checkbox (I have 8 checkboxes):
Private Sub CheckBox1_Click()
[22:25].EntireRow.Hidden = Not CheckBox1
End Sub
On the second worksheet
2. Same as above but on a different sheet, I would like the same result of related rows appearing when checked and disappear when not checked. I am not sure how to refer to another worksheet, and / or if there is a way to insert another line to the above.
Any help is appreciated.

Excel ComboBox Crashing with down arrow keystroke

I have created a ComboBox to do a Google-style search of Cities. I have my ComboBox on sheet 1, that is linked to a dynamic range of cities on sheet 2. The ComboBox output cell is what changes the dynamic range.
Here’s the problem I’m having. I start typing “sea” and I get two results in my drop down list-seaport and Seattle. So far so good. Then I use the down arrow to Select Seattle and the program crashes and restarts. I believe it is because when I hit down one time, seaport is selected and this narrows down my range to just the one option and Seattle disappears.
Is there any way around this? Either disabling the use of the keyboard down arrows for selections or preventing the output to the linked cell until a selection is finalized?
This the code for my combobox on Sheet1
Private Sub TempCombo_Change()
TempCombo.ListFillRange = "Cities"
Me.TempCombo.DropDown
End Sub
The named range "Cities" is defined by formula on sheet 2
='City Data'!$L$2:INDEX('City Data'!$L$2:$L$570,MAX('City Data'!$K$2:$K565,1))

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