Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Exit Combo Box Problem

Status
Not open for further replies.

Quintios

Technical User
Joined
Mar 7, 2002
Messages
482
Location
US
I have a spreadsheet with several pivot tables in it. I have a combo box that, when changed, changes the PAGE setting of the pivot tables. What I learned through trial and error is that you have to select another cell (Range(XX).Select) before the pivot tables will update, so the first thing in my combobox code is:

Code:
Range("A2").Select

This works fine and dandy, however, when I exit the worksheet, for some reason that combo box changes and I get an error because the spreadsheet has closed and Excel attempts to select that range. The error is "Run Time Error 1004, Select Method of Range class failed."

What can I do to skip over this error, or disable it? I can't take the range.select code out because otherwise the VBA errors out because the combo box is selected and the pivot tables can't update.

I tried using an "On Error goto ErrorHandler" and then under ErrorHandler: I put simply Resume Next, which resides just before End Sub. I can close the spreadsheet without error, but then Excel locks up, blank, and just sits there for a while, no doubt going through some stupid endless loop.

Help!! Onwards,

Q-
 
I just had a thought but don't know how to implement it. If I could test to see if the spreadsheet is actually open before selecting that cell, might that fix my problem? I remember that there are various collections in Access for queries, forms, tables, etc. Is there a workbook collection in Excel? I'll check the help files, but any help you can provide in the meantime will allow me to go to bed a little sooner! :-) Onwards,

Q-
 
I fixed it I fixed it!!!

I put the following code that checks the activeworkbook name, and if it isn't the same it won't run the code:

If activeworkbook.name <> &quot;spreadsheet_name&quot; then
exit sub
end if

Cool. Hope this helps someone else in the future.
Onwards,

Q-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top