I have a bit of code I have used for years and recently under a slightly different application we have a bug. in the following code, if cell B4 = "z, row" we need to display the message box and close the form. however, regardless us what I try to Exit Sub I get "Runtime Error 91: Object variable or with block variable not set"
Private Sub UserForm_Initialize()
Dim lastrow As Integer
Dim frmTop As Integer
Dim cbnOfSt As Integer
Dim varAnswer As String
'bail out code
If Range("B4") = "z, row" Then
varAnswer = MsgBox("This worksheet has only one employee. A new employee must be added before the current employee can be removed", _
vbOK, "Minimum Employee Warning")
If varAnswer = vbOK Then
Unload frmRemEmpl, some results with "unload me"
Exit Sub ' RESULTS IN --->"Runtime Error 91: Object variable or with block variable not set"
End If
Else
End If
'form code here
End Sub
I know this is something obvious but not obvious to me. please help
Robert
Bookmarks