Reputation: 49
I keep getting an error:
Run-time error '91; Object variable or with block variable not set.
My script runs fine and does what it needs to do but I can't figure out how to get rid of this error.
Thank you for the help.
Public Sub CommandButton1_Click()
Dim rng As Range
Set rng = Range("F24:I24")
rng.Select
If TextBox1.Text = "" Then
MsgBox ("Must insert Temperature you dingus!")
Else
rng = TextBox1.Text
Call GetCabinet1
End If
Unload Me
End Sub
Public Sub UserForm_Initialize()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = Sheets("Executive Summary")
wb.Activate
ws.Select
UserForm1.Show
Unload Me
End Sub
Upvotes: 0
Views: 217
Reputation: 49
Simply replacing the unload me with me.hide fixed my problem... Thank you to all of those who gave their input....
Upvotes: 0
Reputation: 13386
remove all those Unload.Me
from both your subs and place it in the sub calling that userform
place a Me.Hide
by the end of CommandButton1_Click(), instead
finally remove UserForm1.Show
from UserForm_Initialize
since it'd make it repeat twice
so your "Main" sub would look like:
Sub main()
Dim UF As UserForm1
Set UF = New UserForm1
UF.Show
Unload UF ' unload the userform from here
End Sub
and your userform1 code like:
Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = Range("F24:I24")
rng.Select
If TextBox1.Text = "" Then
MsgBox ("Must insert Temperature you dingus!")
Else
rng = TextBox1.Text
Call GetCabinet1
End If
Me.Hide
End Sub
Public Sub UserForm_Initialize()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = Sheets("Executive Summary")
wb.Activate
ws.Select
End Sub
Upvotes: 2