JLSHARP92
03-09-2011, 01:51 PM
So I have my macro code and a great big thanks to xld for making it possible for me, but I have another problem. I need to leave a message above each piece of code starting with ' in order to make the system more effective and to understand more what the code means. If somebody could help me with putting the messages above the code that would be a great help. Thank you
Sub LogIn()
'stops the screen from flickering
Application.ScreenUpdating = False
'declares variables
Dim uname As String
Dim pword As String
Dim rng As Range
'moves worksheet and sets values to variables
Sheets("LogInForm").Select
uname = Range("Username")
pword = Range("Password")
'if values are not empty
If uname <> "" And pword <> "" Then
With Sheets("UserDetails")
On Error Resume Next
Set rng = .Columns(1).Find(uname)
On Error Goto 0
If Not rng Is Nothing Then
Sheets("LogInForm").Range("Username") = ""
Sheets("LogInForm").Range("Password") = ""
If pword = rng.Offset(0, 1).Value Then
'move worksheets and reset values , then moves sheets
Sheets("MainMenu").Select
Application.ScreenUpdating = True
Exit Sub
End If
MsgBox "Please try again, You must enter a valid username and password", vbOKOnly
End With
Else
MsgBox "You must enter both a username and password"
End If
Application.ScreenUpdating = True
End Sub
Sub LogIn()
'stops the screen from flickering
Application.ScreenUpdating = False
'declares variables
Dim uname As String
Dim pword As String
Dim rng As Range
'moves worksheet and sets values to variables
Sheets("LogInForm").Select
uname = Range("Username")
pword = Range("Password")
'if values are not empty
If uname <> "" And pword <> "" Then
With Sheets("UserDetails")
On Error Resume Next
Set rng = .Columns(1).Find(uname)
On Error Goto 0
If Not rng Is Nothing Then
Sheets("LogInForm").Range("Username") = ""
Sheets("LogInForm").Range("Password") = ""
If pword = rng.Offset(0, 1).Value Then
'move worksheets and reset values , then moves sheets
Sheets("MainMenu").Select
Application.ScreenUpdating = True
Exit Sub
End If
MsgBox "Please try again, You must enter a valid username and password", vbOKOnly
End With
Else
MsgBox "You must enter both a username and password"
End If
Application.ScreenUpdating = True
End Sub