VBA to reset dependent Combo Box cell link value

Ngamia

New Member
Joined
Apr 26, 2021
Messages
20
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Scenario:
The user selects a region (Dropdown1) then gets to choose from the filtered product codes list (Dropdown4) to populate the sales data sheet. The problem is, when you change the region, the product code list remains at whatever row number had been set previously.

I need a macro that resets the value of a dependent Combo Box (Form Control) to 1 whenever the main Combo Box (Dropdown1) changes (irrespective of the change value).

The settings for the two boxes are shown below.
DropDown1 (Region)
INPUT RANGE: $S$2:$S$10
CELL LINK: $E$3

DropDown4 (Product Code)
INPUT RANGE: U:U
CELL LINK: $E$5

The values in the Input Ranges are simply hard-coded filtered lists based on the value in the cell link. For example, the data in column U is derived as follows:
Excel Formula:
 IF($E$3=4,FILTER(Product_Code, Region=$T$4))


I am using the following code to reset Dropdown 1 whenever the document is opened:

VBA Code:
    Private Sub Workbook_Open()
        Worksheets("Sheet1").Range("E3") = 1
    End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

If you are using Form ComboBox in your worksheet ...
VBA Code:
Sub ResetFormDropDown()
Dim dd As DropDown
Set dd = ActiveSheet.Shapes("Drop Down 1").OLEFormat.Object
dd.ListIndex = 1
End Sub
 
Upvote 0
Solution
Thanks @James006. This is exactly what I needed. It works perfectly.

Being a VBA noob, it took me a while to figure out how to get it to work.
To assist those coming after me, this is what you do:

- Edit the code provided by @James006 so that ("Drop Down 1").OLEFormat.Object references the Combo Box you want to reset. In my case this was Dropdown4, so I changed the line to ("Drop Down 4").OLEFormat.Object

- Right click on the sheet with your dropdown and select "View Code" from the menu

- add the code above to the window that opens

- Right click on the main combo box (the one that controls the reset) and select "Assign Macro..."

- The list should now include the code you just added (.ResetFormDropDown)

- Click on the name (.ResetFormDropDown) to assign it to the Combo Box

- Click Ok.

I hope this is makes sense.
 
Last edited:
Upvote 0
Pleased to hear you have managed to solve your problem :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top