I'm working out a dashboard for my office. It all works, but I wanted to add in an option that instead of searching through 250+ items in a dropdown, you could also click on a cell and the dropdown would change to that value, and the assigned macro would run for that dropdown. So far I can't figure out how to have vba select a specific item from a dropdown. I can have the text change, but that doesn't select the index of the dropdown.
Any suggestions?
If you are using an ActiveX drop down list, (a combobox) this is how you would change the selected value in the drop down list:
ComboBox1.Value = "New Value"
If you are using data validation as a drop down list, then you just need to change the cell value as you would change any other cell:
'assuming the drop down list (data validation) is in Cell(1, 1)
cells(1,1) = "New Value"
Also you could check this article I've written on my blog about working with drop down lists in VBA Excel VBA Drop Down Lists
I wanted to do the same: Select an option from several drop down lists, then "reset" all of them to a starting point. Recording a macro and change the drop down list wont work.
However, I did the following:
Start recording macro
I typed all the values I wanted to be the "starting point once reset on the drop down list
stop macro.
It worked. Now I hit the macro and I get all the values "reset". Cheap trick, I know but worked for me.
Related
I am aware that this thread already exists:
Hide DropDown list for ComboBox without losing focus
But unfortunately, it is for a UserForm and isn't applying to my questions.
My situation is rather on a Worksheet like below:
In fact, to show that dropdown list, here is what I did:
shLedgerImport.CboAcctCode.DropDown 'This function shows the dropdown list
But once it appears, I cannot hide it anymore:
---> I just want it to hide that dropdown list when I click on E2, of H5 or anywhere except E9 that is the ActiveCell.
(In case the user displayed it by mistake and want it to hide, what they need to do? Escape key isn't working, Click elsewhere isn't working)
Thank you
I have a large file with a Scenario Manager, where changing a single cell on the Summary worksheet changes the visible scenario throughout the rest of the workbook. Data Tables are working a treat providing the headline values for each option.
I'd like to have a drop down on each sheet that when changed will change the same single cell on the Summary worksheet, so I don't need to go back to the Summary sheet every time I want to switch visible scenarios.
This is a simple process if I'm using macros and would be the solution I'd normally jump straight to. But this needs to be done without macros and this is where I'm now struggling.
Does anyone know if this is possible (without macros) and point me in the right direction?
Josh
You can insert combo box (Developer Tab > Insert > Form Controls > Combo Box) on each sheet. Mention linked cell as a cell of the summary sheet (Absolute reference with sheet name). That cell will give you index of the item selected in the drop down list. Then you can insert index formula in the cell you want to change every time to get value of the drop down list. Once you insert it on one sheet you can copy it to other sheets. No macros required.
I have made a userform using macros in excel.
The code is independent from excel (it does not read the data from excel).
Once the userform opens, I populate the combobox with few items in it by:
combo.additem "a"
combo.additem "b"
combo.additem "c"'
From what I found, in order to make the combobox uneditable, I need to change the style of the list to drop downlist.
However, once I have done so, my combobox options turns to be:
"" (blank cell)
a
b
c
Is there an option to keep the combobox uneditable without adding the first empty cell?
Thank you
The combobox will become an uneditable dropbox when you change its Style to 2 - fmStyleDropDownList.
Add .ListIndex=0 to your code to make the dropbox come up with no empty field and have the first item displayed as the default.
I'm wanting to have a an excel spreadsheet automatically fill in a dropdown selection based on a previous dropdown.
Basically i have a spreadsheet that allows me to pick colours of items from basic dropdown lists each row has its own dropdown. Often the colours are the same so would like it to automatically fill in the next rows colour the same as the previous lines for me?
anyone have any ideas? Can't seem to find much on only filling out the dropdown? Also is there a method to fill out all dropdowns simultaniously?
Thanks
There are two approaches to this depending on what you mean by 'drop-down'.
If you are using a 'form control' drop-down then you have the option under right-click>Format Control... to specify a cell whose value will be set when you change the drop-down selection. You can then use this value to affect other areas of your spreadsheet.
If your drop-down is done using the 'Data Validation' then it will only affect the cell you have put it in. In this case you will have to turn to VBA.
For this you would use the Worksheet_Change event and an If statement checking that the Target is the drop-down cell, then you can code the filling in of your other dropdowns. Check out this microsoft guide for triggering VBA from cell changes.
I have a Drop Down in excel sheet. It has the values
NEW
DELETION
SUSPENDED
I want to make use to these values to perform some action. Say like if the value of the Cell is NEW is should check that and then work further.
when I write below code in VBA it doesn't work.
If Sheet5.Range("B16").Value = "NEW" Then
.... Perform some action...
Won't the above line work? Can't I compare the Value to "NEW".
Please note: The drop down is in excel sheet. How do I retrieve this Excel sheet dropdown value in macros?
This is not a dropdown, it's a Validation List, which is created from the Data ribbon like:
So the underlying cell, in your case E1, behaves like a normal cell except it can only accept certain values. You can access its properties in VBA as expected, for instance:
Debug.Print Range("E1").Value
So, your code should work if you call the macro from the Developer|Macros menu, or if you run it from the VBE using F5 key.