Combobox change event and workbook close/open

charisma7

New Member
Joined
Jan 5, 2017
Messages
5
I hope I can explain this properly.

I have a combobox_change sub that amends two fields depending on the value of what's selected. Those fields, however, are unlocked and able to be overwritten by the user.

The problem is that this change event seems to be running upon either workbook close and/or open, as after saving, closing, and re-opening, the fields are replaced with the values that would be provided based upon the combobox_change code, and NOT what the user may have subsequently typed.

Is there any way to either prevent this code from running upon workbook close/open...or any other ideas/workarounds?

I thought of possibly writing workbook open and beforeclose events to lock those fields and therefore prevent changes, but that seems more difficult than necessary.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I hope I can explain this properly.

I have a combobox_change sub that amends two fields depending on the value of what's selected. Those fields, however, are unlocked and able to be overwritten by the user.

The problem is that this change event seems to be running upon either workbook close and/or open, as after saving, closing, and re-opening, the fields are replaced with the values that would be provided based upon the combobox_change code, and NOT what the user may have subsequently typed.

Is there any way to either prevent this code from running upon workbook close/open...or any other ideas/workarounds?

I thought of possibly writing workbook open and beforeclose events to lock those fields and therefore prevent changes, but that seems more difficult than necessary.


Can you give a specific example of what is going on?

What are these two fields you are mentioning?

Do you have any code in ThisWorkbook for Open, BeforeSave, AfterSave, or Before Close?
 
Upvote 0
Can you give a specific example of what is going on?

What are these two fields you are mentioning?

Do you have any code in ThisWorkbook for Open, BeforeSave, AfterSave, or Before Close?

Thanks for your reply.

The "fields" are just cells that are populated with numbers based upon a vlookup (value of combobox is found in vlookup to grab the numbers that populate the cells) that runs on the combobox_change event.

Those cells may be filled with 1.50 (or anything), but the cells are unlocked and the user can type over them if they like.

The problem is that the cells may pre-fill with 1.50, then typed over with 1.10. I save the workbook, close, then re-open. At that time, the cell is back to 1.50.

I can only assume it's because it's running the combobox_change event upon either open or close.
 
Upvote 0
Sure thing!

Code:
Private Sub ComboBox1_Change()
Dim targetRange1 As Range
Dim targetrange2 As Range
Dim classsurcharge As Single
Class = Range("Class")
Set targetRange1 = Range("Liability_Class")
Set targetrange2 = Range("PD_Class")
If Class = "(Select)" Then
targetRange1.Value = ""
targetrange2.Value = ""
Else
classsurcharge = Application.VLookup(Class, Range("Class_Surcharges"), 2, False)
targetRange1.Value = Format(classsurcharge, "Fixed")
targetrange2.Value = Format(classsurcharge, "Fixed")
End If
End Sub
 
Upvote 0
FYI - I was able to solve this, and am posting for anyone else who may experience the same issue.

First, I declared a global Boolean variable (in this case, I used gblnDD) in an existing module.

Next, I set up a new event procedure for ComboBox1_DropButt******* to set the gblnDD to True.

Then in my existing Combobox1_Change event, I added a check to see if gblnDD is True before executing my code. Then set it back to false after.

Now, the Combobox1_Change event is only triggered if the combobox has been dropped down by clicking on it first. No other system events will allow it to execute.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

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