ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   close UserForm (https://www.excelbanter.com/excel-programming/376057-close-userform.html)

[email protected]

close UserForm
 
Received a runtime 91 error "Object variable or With block variable not
set" error when closing an user form. Excel debug go right to 'Load
UserForm1" statement. All code run smoothly up to this point.

Help!


Tom Ogilvy

close UserForm
 
Sounds like you have an error in your code where you try to use an object
that is not set to a reference. Probably in some code that fires when the
userform is closed.

for instances if you had

Private Sub Cmd_OK_Click()
rng.Value = Textbox1.Value
Unload me
End sub

if rng was not pointing to a range object, you would get such an error.

--
Regards,
Tom Ogilvy




" wrote:

Received a runtime 91 error "Object variable or With block variable not
set" error when closing an user form. Excel debug go right to 'Load
UserForm1" statement. All code run smoothly up to this point.

Help!



Chip Pearson

close UserForm
 
Without seeing the code in the UserForm_Terminate event, it is difficult to
determine the cause of the problem. In order to have the editor take you to
the offending line of code, in VBA go to the Tools menu, choose Options,
then the "General" tab. There, select "Break In Class Module" instead of
"Break On Unhandled Errors".


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)

wrote in message
oups.com...
Received a runtime 91 error "Object variable or With block variable not
set" error when closing an user form. Excel debug go right to 'Load
UserForm1" statement. All code run smoothly up to this point.

Help!




katrina

close UserForm
 
I'm having the same problem unloading a userform...thought until last night
that error 91 was caused by trying to show a highlighted default in the
listbox because without the line .ControlSource = "Sheet1!AA19" everything
worked fine. Last night I discovered the default and everything else worked
without the Unload Me command except that the userform won't unload (Duh!) I
tried Unload CropMonth, which is the name of the userform but I get the same
error. It's a userform with only a single selection listbox which I want to
default to the last selection when it initializes and close when the user
clicks a selection. Here's the code:

Private Sub ListBox1_Click()
Sheets("sheet1").Range("AA19").Value = ListBox1.Value
Unload Me '(everything works w/o this line except won't unload
form.)
End Sub

Private Sub UserForm_Initialize()
With ListBox1
.RowSource = ""
.AddItem "N/A"
.AddItem "January"
.AddItem "February"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
.ControlSource = "sheet1!AA19" '(Everything works w/o this but no
default.)
End With
End Sub

I would also appreciate any help regarding this problem. Thanks, Katrina


All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com