I have an error and I cant figure it out ... please help

Option Explicit

Sub pass()

Dim user As String, pass As String
Dim rguser, rgpass As Range
Dim found As Boolean
Dim x As Integer
Dim newpass As Boolean
Dim yesno As String
Dim i As Long
Dim passpos As Range
Dim rowuser As String

Set rguser = Range("a1")
Set rgpass = Range("b1")
found = False

user = InputBox(" please enter your user name ")
pass = InputBox("please enter a vald password ")

Do While user = "" Or pass = ""
MsgBox ("you have to enter a valid information ")
user = InputBox(" please enter your user name ")
pass = InputBox("please enter your password ")
Loop

For x = 0 To 10
If rguser.Offset(x, 0).Value = user Then
rowuser = x
found = True
Else: MsgBox "the user are not found !!"
End If
Next

If rguser.Offset(rowuser, 1) = pass Then
passpos = pass.Range

Else: MsgBox "the password is not valid, please contact IT !! "

End If

yesno = MsgBox("do you want to change you password ? ", vbYesNo, "changing password")

If yesno = vbYes Then
Do While i = 1

newpass = InputBox(" please enter your new password ")
If Not Len(newpass) = 8 And (Left(newpass, 1) Like "[A-Z]" And i <= 7) Then
MsgBox (" your password shoud be 8 characters start with an uppercase leter, and cosist of uppercase letter and digits with no space ")
End If
Loop
End If

If Len(newpass) = 8 And (Left(newpass, 1) Like "[A-Z]" And i <= 7) Then
pass = passpos.Value
End If

If yesno = vbNo Then
MsgBox " you have to change you password as soon as possiable "
End If

End Sub

what Im trying to do

solving this question :

the user and the password are already in the sheet , when you run the macro it should ask for user name and the password then the user can change the password but the new password must be 8 characters long, start with an uppercase letter, and consist of uppercase letters and digits with no space .

Vishesh's picture

Compile time error in your code

What are you trying to achieve with this code ?

Check this line in your code
passpos = pass.Range

Its syntactically incorrect.

I rewrite the code but still have the error

Option Explicit

Sub login()

Dim User, Pass As String
Dim Find As Boolean
Dim X, rowNbr As Integer
Dim RNguser As Range
Dim Yesno As String
Dim Newpass As String

Set RNguser = Range("a1")
Find = False

'loop log in
Do
User = InputBox(" please log in with a valid user name ")
Pass = InputBox("please enter your valid password ")
Loop While User = "" Or Pass = ""

' check the user i its registered

For X = 0 To 100
If RNguser.Offset(X, 0).Value = User Then
rowNbr = X
Find = True
If RNguser.Offset(rowNbr, 1) = Pass Then
MsgBox " u loged in succsefully "
Yesno = MsgBox("welcom " & User & vbNewLine & "do you want to change you password ? ", vbYesNo, "changing password")
End If
End If
Next

'change pass
If Yesno = vbYes Then
Do While X = 1
Newpass = InputBox(" please enter your new password ")
If Len(Newpass) = 8 And (Left(Newpass, 1) Like "[A-Z]" And X <= 7) Then
RNguser.Offset(rowNbr, 1).Value = Pass
MsgBox "your password have been changed sucessfully "

Else

'If Not Len(newpass) = 8 And (Left(newpass, 1) Like "[A-Z]" And i <= 7) Then
MsgBox (" your password shoud be 8 characters start with an uppercase leter, and cosist of uppercase letter and digits with no space ")

If Yesno = vbNo Then
MsgBox " you have to change you password as soon as possiable "

'End If
End If

End If

'ends

End Sub