I am having this really strange error in excel VBA that keeps showing up. I used the codes below
Public psword, oldpsword As Integer
Public Sub Auto_Open()
psword = Sheets("Main Menu").Cells(55, 1)
oldpsword = psword
For Each ws In Worksheets
ws.Protect Password:=psword
Next ws
End Sub
Whenever the code goes to the line "oldpsword = psword" an error message pops up showing Run-time '13:' type mismatch error. How can i fix it?
Public psword, oldpsword As IntegeronlyoldpswordisIntegerwhilepswordisVariant. Redim itPublic psword As integer, oldpsword As IntegerDimstatement. However, I suspect the problem is thatCells(55,1)does not contain an integer. A variant can contain anything sopsWord = ...is OK butoldpsword = pswordfails because the value inpswordcannot be converted to a integer.