Error in VBA coding excel, login and security check

Muhammad Taqi 6 Reputation points
2022-04-11T10:52:04.74+00:00

Hi everyone. Please help me to debug errors in Login and Security code of VBA in excel.
Code is below. I have tried to highlight code error in closed stars which were shown after debug.

Option Explicit

Sub CheckUser()
Dim UserRow, SheetCol As Long
Dim SheetNm As String
With Sheet1
.Calculate

If .Range("B8").Value = Empty Then 'Incorrect Username
MsgBox "Please enter a correct User name"
Exit Sub
End If

If .Range("B7").Value <> True Then 'Incorrect password
MsgBox "Please enter a correct password"
Exit Sub
End If

LoginForm.Hide
.Range("B5,B6").ClearContents
UserRow = .Range("B8").Value 'User Row

For SheetCol = 8 To 13
SheetNm = .Cells(4, SheetCol).Value 'Sheet Name
If .Cells(UserRow, SheetCol).Value = "Ð" Then
Sheets(SheetNm).Unprotect "123"
Sheets(SheetNm).Visible = xlSheetVisible
End If

If .Cells(UserRow, SheetCol).Value = "Ï" Then
Sheets(SheetNm).Protect "123"
Sheets(SheetNm).Visible = xlSheetVisible
End If

If .Cells(UserRow, SheetCol).Value = "x" Then Sheets(SheetNm).Visible = xlVeryHidden
Next SheetCol
End With
End Sub

Sub CloseWorkbook()
Sheet6.Activate
Dim WkSht As Worksheet
For Each WkSht In ThisWorkbook.Worksheets
If WkSht.Name <> "Start" Then WkSht.Visible = xlSheetVeryHidden
Next WkSht
ThisWorkbook.Save
End Sub

Microsoft 365 and Office Development Other
Developer technologies Visual Basic for Applications
0 comments No comments
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.