Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

excel - Error 91: Object variable or With block variable not set on Unload Me

My problem is that I try to use the "Unload Me" option, but I constantly receive an error that says "Object variable or With block variable not set". There's no error when I'm going to remove the Unload Me.

If i = 0 Then
   MsgBox "The learner has not yet been graded for this quarter!", vbOKOnly + vbInformation
   Unload InputGrds
End If

The flow that I'm thinking is that if the IF statement above is equals 0 then there will be a MsgBox that will say that the learner is not yet graded and the UserForm with a filename InputGrds will not appear.

Private Sub UserForm_Initialize()
    
    With InputGrds
        .StartUpPosition = 0
        .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
        .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    End With
    
    txtBox_LRN.Text = CStr(ThisWorkbook.Sheets("HOME").Range("K11").Value)
    txtBox_lname.Text = CStr(ThisWorkbook.Sheets("HOME").Range("K12").Value)
    txtBox_grd.Text = CStr(ThisWorkbook.Sheets("HOME").Range("K16").Value)
    txtBox_qrt.Text = CStr(ThisWorkbook.Sheets("HOME").Range("K17").Value)
    
    grd = txtBox_grd.Text
    
    Select Case grd
        Case "1"
           result = "Matthew"
           tb_epp.Enabled = False
        Case "2"
           result = "Mark"
           tb_epp.Enabled = False
   End Select
   
   txtBox_sec.Text = result
   
    If ThisWorkbook.Sheets("HOME").Range("A1").Value = "I" Then
        Label1.Caption = "INPUT GRADES"
    ElseIf ThisWorkbook.Sheets("HOME").Range("A1").Value = "U" Then
        Label1.Caption = "UPDATE GRADES"
        btnSave.Caption = "UPDATE"
        
        Set ws = ActiveWorkbook.Worksheets("G1-Q1")
        lastrow = ws.Cells(Rows.Count, "C").End(xlUp).Row
        
        Dim i As Integer
        i = 0
        
        For r = 10 To lastrow
        
            If ws.Cells(r, 3) = CStr(ThisWorkbook.Sheets("HOME").Range("K11").Value) Then
                tb_mtb.Text = ws.Cells(r, 9).Value
                tb_fil.Text = ws.Cells(r, 10).Value
                tb_eng.Text = ws.Cells(r, 11).Value
                tb_math.Text = ws.Cells(r, 12).Value
            End If
            i = i + 1
        Next r
        
        If i = 0 Then
            MsgBox "The learner has not yet been graded for this quarter!", vbOKOnly + vbInformation
            Unload InputGrds
        End If
    End If
End Sub

Here's the Module code

Sub Input_Grds()
    If Not IsEmpty(Range("K16").Value) And Not IsEmpty(Range("K17").Value) Then
        InputGrds.Show 'When I clicked the Debug button, this is the highlighted line
    Else
        MsgBox "Please enter a data in the SELECT DATA table.", vbRetryCancel + vbCritical, "SF10"
    End If
End Sub
question from:https://stackoverflow.com/questions/65932285/error-91-object-variable-or-with-block-variable-not-set-on-unload-me

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...