VBA type mismatch error

MH Shimanto 1 Reputation point
2022-02-01T13:27:04.993+00:00

Hello there , I am trying to create an excel app on VBA, it is showing Run-time error 13: Type Mismatch error

If anyone could help me would be very nice of you :)

The code is below:

'work with the lock/unlock button on admin starts
For SheetCol = 5 To 11

SheetNm = .Cells(2, SheetCol).Value 'Sheet Name
If .Cells(UserRow, SheetCol).Value = "Ð" Then
Sheets(SheetNm).Unprotect "5896"
Sheets(SheetNm).Visible = xlSheetVisible

End If

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

Next SheetCol
End With
'work with the lock/unlock button on admin ends

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. John Korchok 4,926 Reputation points
    2022-02-01T14:55:23.583+00:00

    When you get the run-time error, there is a Debug button on the dialog. Click on that. The VBE window will open with the line containing the error highlighted in yellow. Which line of your code is it?


  2. John Korchok 4,926 Reputation points
    2022-02-01T18:16:41.733+00:00

    A type mismatch error always indicates that you are using the wrong kind of variable. Excel is expecting a Variant variable for a cell value, not a string. Using CVar("Ð") should fix that. Type conversion functions

    But you haven't included your Dim statement for UserRow, make sure that variable is numeric as well.