【问题标题】:VBA Error "Object variable or with block variable not set "VBA 错误“对象变量或未设置块变量”
【发布时间】:2019-12-15 20:27:39
【问题描述】:
Private Sub LoginMasuk_Click()
Dim Password As String 
Dim Level As String
Dim pass As String  

pass = MD5(TextBox2.Value) 
Set WsUserName = Sheets("Data")
Set RgUserPas = WsUserName.Range("A2:A20")
Set c = RgUserPas.Find(TextBox1.Value, LookIn:=xlValues, MatchCase:=False)

Password = c.Offset(0, 1).Value
Level = c.Offset(0, 2).Value 

If pass <> Password Then
    MsgBox "password yang anda masukan salah", vbCritical, "User Login"
    Exit SubElse
    If Level = "Admin" Then
        MsgBox "Selamat Datang " & TextBox1.text, vbInformation, "Message"
        'MsgBox "Anda Login Sebagai " & Level, vbInformation, "User Login"
            loginApp.Hide
                Sheets("Data").Visible = xlSheetVisible
                Sheets("Hai").Visible = xlSheetVisible
                Sheets("Halo").Visible = xlSheetVisible
            Menu_Admin.Label1.Caption = Level
            Menu_Admin.Show
        Call bersih
        Exit Sub
    ElseIf Level = "Siswa" Then
        MsgBox "Selamat Datang " & TextBox1.text, vbInformation, "Message"
        'MsgBox "Anda Login Sebagai " & Level, vbInformation, "User Login"
            loginApp.Hide
                Sheets("Data").Visible = xlSheetVeryHidden
                'Sheets("Data").Visible = xlSheetVisible
                Sheets("Hai").Visible = xlSheetVisible
                Sheets("Halo").Visible = xlSheetVisible
                Menu_Siswa.Label1.Caption = Level
                Menu_Siswa.Show
        Call bersih
        Exit Sub
    End If
End If
End Sub

我在代码中遇到错误 -->

Password = c.Offset(0, 1).Value

我是怎么解决的

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    首先检查您的.Find 呼叫是否确实找到了一些东西。把它放在那一行之前:

    If c Is Nothing Then
      Msgbox "'" & TextBox1.Value & "' was not found"
      Exit Sub
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多