Why does VBA code in Private Sub kep running?

G

Guest

Guest
I'm using MS Excel 97. A worksheet has a combo box with vba code associated with it. When the combo box changes, so does data on a chart.

The problem, however, is that the code in the combo box runs when I close the file. Why? (I don't want the code to run. Plus, I don't have any code elsewhere in the file where the OnClose event is used.) I don't understand why this happens when the code is in a private sub within the combo box control.

Can anyone explain, and come up with a solution?

Thanks,
Pete
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I think you're going to have to give more details. Is it the combobox from the Control Toolbox? Are you adding items through code or is it linked to a range? It would also be helpful if you post both the combobox code and the Before_Close code.

Regards,
D
 
Upvote 0
Yes, the combobox is from the Control ToolBox, and the items listed are from a range.

Here's the code for the combobox:
(where the selection changes the pagefield
of a pivot table)

<start code>
Private Sub cboHARP_Change()

Application.ScreenUpdating = False
ActiveCell.Activate
ActiveSheet.PivotTables("pivotMEMBERSHIP").PivotFields("HARP").CurrentPage = cboHARP.Value

If cboHARP.Text <> "ALL GRIPA" Then
Range("c14") = cboHARP.Text
Else
Range("c14") = "GRIPA"
End If

Range("A1").Activate
Application.ScreenUpdating = True

End Sub
<end code>


As for code in the BeforeClose event, there is none:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
End Sub

So, give the above info, what is triggering the code in the combobox private sub when closing the file?

Thanks,
Pete

On 2002-02-27 10:51, dk wrote:
I think you're going to have to give more details. Is it the combobox from the Control Toolbox? Are you adding items through code or is it linked to a range? It would also be helpful if you post both the combobox code and the Before_Close code.

Regards,
D
 
Upvote 0
There's nothing that leaps out at me. I'll gladly have a look at the workbook if you want to send it (of course strip out any data you don't want others to see).

dklann@lineone.net

Regards,
D
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

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