help with 91 error

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am getting an object variable or with block variable not set error when I add this line "Unload DataEntryElGr" to my code and I can't figure out why, the code runs perfect until I add it....

The sub is in the "DataEntryElGr" userform, The purpose of this string is simply to close the form instead of having to click on the "X". I appreciate any input - thanks,


Code:
Private Sub UserForm_Initialize()
    Dim i As Long
    Dim Lastrow As Long
    'this is from the DEVICE ID column
    
    If ThisWorkbook.Sheets("Emergency Lighting Log").Range("M1").Value = 0 Then
    MsgBox " All emergency lighting has been inspected in this area, please continue on to the next inspection area. "
    
    EmergencyLightArea.Show
    
[COLOR=#ff0000]    Unload DataEntryElGr[/COLOR]
        
       
    Else
      
        Lastrow = Cells(Rows.Count, "L").End(xlUp).Row
         For i = 1 To Lastrow
             If Cells(i, 15).Value = "" Then ListBox1.AddItem Cells(i, 12).Value
         Next
         Me.TextBox4.Text = CStr(ThisWorkbook.Sheets("Emergency Lighting Log").Range("M1").Value)
    
        TextBox1.SetFocus
    End If
    
    
End Sub
 
Well the obvious place to put the code that determines whether or not a userform is displayed is in the code that currently displays the userform.

What I mean is have something like this in the code of the command button that shows the userform.

Code:
Private Sub AButton_Click()

    If ThisWorkbook.Sheets("Emergency Lighting Log").Range("M1").Value = 0 Then
        MsgBox " All emergency lighting has been inspected in this area, please continue on to the next inspection area. "
    
        EmergencyLightArea.Show
          
    Else
        DataEntryElGr.Show
    End If

End Sub
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Yes of course, put it in the sub that calls the userform not the sub that runs the userform - totally makes sense - (almost a duh moment - lol) I am sure that this is the solution. Thanks for the advice on that Norie, you have helped me once again :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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