Run time error 13

clouie

New Member
Joined
Mar 11, 2019
Messages
8
I have a codes below for my simple log.When I try to run it I got an error message Run-Time error'13' Type mismatch. I don't know what is the problem. Thanks if someone can help me on this.

Code:
Dim UserRow, SheetCol As Long
Dim SheetNm As String
With Sheet1
.Calculate


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
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the forum.

Which line is highlighted when you get the error? The most likely cause I can think of currently is that you have an error value in one of the cells you are testing.
 
Upvote 0
Welcome to the forum.

Which line is highlighted when you get the error? The most likely cause I can think of currently is that you have an error value in one of the cells you are testing.


Thanks Mr. RoryA for your quick response. The error I got is in this line below.

If .Cells(UserRow, SheetCol).Value = "Ð" Then
 
Upvote 0
Do you have errors in your sheet? If so, you need to test for that first:

Code:
For SheetCol = 8 To 13
SheetNm = .Cells(4, SheetCol).Value 'Sheet Name
If Iserror(.Cells(UserRow, SheetCol).Value) then
' ignore
Else
   Select Case .Cells(UserRow, SheetCol).Value
       Case "Ð", "Ï"
           Sheets(SheetNm).Unprotect "123"
           Sheets(SheetNm).Visible = xlSheetVisible
       Case "x"
            Sheets(SheetNm).Visible = xlVeryHidden
    End Select
End If
Next SheetCol
End With
 
Last edited:
Upvote 0
That's not what I asked. I asked if you have errors in the worksheet itself (e.g. #NAME, #VALUE , #REF , #N/A etc). The code I posted above should cater for errors in the sheet.
 
Last edited:
Upvote 0
Yes Mr. RoryA, in this line below is highlighted yellow and the error message is Run-time error 13, type mismatch

If .Cells(UserRow, SheetCol).Value = "Ð" Then

Mr. Rory, I got a new error message. Under the line below.

Error message: Run-time error 1004, Application-defined or object-defined error
Under line: If IsError(.Cells(UserRow, SheetCol).Value) Then
 
Upvote 0
Please post your full code, and tell me what the value of UserRow is.
 
Upvote 0
Please post your full code, and tell me what the value of UserRow is.

Hi Mr. Rory, below is the complete code.
Code:
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 username"
    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").ClearContents


UserRow = .Range("B8").Value 'User Row


For SheetCol = 8 To 13
SheetNm = .Cells(4, SheetCol).Value 'Sheet Name
If IsError(.Cells(UserRow, SheetCol).Value) Then ' ignore
Else
   Select Case .Cells(UserRow, SheetCol).Value
       Case "Ð", "Ï"
           Sheets(SheetNm).Unprotect "123"
           Sheets(SheetNm).Visible = xlSheetVisible
       Case "x"
            Sheets(SheetNm).Visible = xlVeryHidden
    End Select
End If
Next SheetCol
End With
End Sub
 
Last edited by a moderator:
Upvote 0
Please change this line:

Rich (BB code):
Dim UserRow, SheetCol As Long

to this:

Rich (BB code):
Dim UserRow As Long, SheetCol As Long

and then run the code again.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,207,105
Messages
6,076,580
Members
446,215
Latest member
userds5593

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