VBA clear selection of dropdown list upon closing file

tidepooler

New Member
Joined
Jun 24, 2024
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I am attempting to set up my Excel workbook/worksheet (not a user form) to clear a dropdown box when the file is closed. Right now, every time I close the file and reopen it, the last selection in the dropdown is shown. I want this to be clear.

I may also need to change this in the dropdown box's properties, but I have been going down the rabbit hole with VBA code. The problem is that I cannot seem to figure out which event I can apply code to that allows me to use the object name and set its value equal to "".

Thanks in advance!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Are you talking about a Data Validation dropdown list, an ActiveX ComboBox or a Form ComboBox?
 
Upvote 0
Please try this. It needs to be placed in the THISWORKBOOK module. Replace "ComboBox1" the name of your ComboBox
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Sheet1.ComboBox1.ListIndex = -1
End Sub
 
Upvote 1
Solution
Thank you so much, Jeffrey! Sorry for the delay - I have several projects going and I got distracted by another one before I could get back to this.

This worked perfectly.

Now I'm wondering if there is a way to save the file upon closing as well and avoid the "Save File" dialog box...?
 
Upvote 0
👆

My research turned up the code for the saving issue, so I'm good! Thanks again.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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