Kiwi-123
asked on
VB help
Please can you help me add a password for the macro to execute, if "abc" is entered then the code will function, if not a msgbox will state "wrong password" and exit the macro.
Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Dim i As Long
Dim j As Long
Dim row As Range
If InputBox("Please enter the password", "Enter Password") <> Worksheets("Datasheet").Ra nge("B4") Then
MsgBox "incorrect Password."
Exit Sub
End If
j = Sheets("Archive").Range("B " & ActiveSheet.Rows.Count).En d(xlUp).ro w + 1
For i = 9 To ActiveSheet.Range("B" & ActiveSheet.Rows.Count).En d(xlUp).ro w
Set row = ActiveSheet.Range("A" & i)
If row.Cells(1, 14).Value <> "" Then
Sheets("Archive").Unprotec t Sheets("DataSheet").Range( "B5").Valu e
Sheets("Archive").Range("B " & j & ":s" & j).Value = ActiveSheet.Range("B" & i & ":S" & i).Value
j = j + 1
Sheets("Archive").Protect Sheets("DataSheet").Range( "B5").Valu e
End If
Next i
'Delete the archived rows
For i = ActiveSheet.Range("B" & ActiveSheet.Rows.Count).En d(xlUp).ro w To 9 Step -1
Set row = ActiveSheet.Range("A" & i)
If row.Cells(1, 14).Value <> "" Then
Sheets("Low Volume").Unprotect Sheets("DataSheet").Range( "B4").Valu e
row.Rows(1).EntireRow.Dele te
Sheets("Low Volume").Protect Sheets("DataSheet").Range( "B4").Valu e
Application.ScreenUpdating = True
End If
Next i
End Sub
Private Sub CommandButton3_Click()
Application.ScreenUpdating
Dim i As Long
Dim j As Long
Dim row As Range
If InputBox("Please enter the password", "Enter Password") <> Worksheets("Datasheet").Ra
MsgBox "incorrect Password."
Exit Sub
End If
j = Sheets("Archive").Range("B
For i = 9 To ActiveSheet.Range("B" & ActiveSheet.Rows.Count).En
Set row = ActiveSheet.Range("A" & i)
If row.Cells(1, 14).Value <> "" Then
Sheets("Archive").Unprotec
Sheets("Archive").Range("B
j = j + 1
Sheets("Archive").Protect Sheets("DataSheet").Range(
End If
Next i
'Delete the archived rows
For i = ActiveSheet.Range("B" & ActiveSheet.Rows.Count).En
Set row = ActiveSheet.Range("A" & i)
If row.Cells(1, 14).Value <> "" Then
Sheets("Low Volume").Unprotect Sheets("DataSheet").Range(
row.Rows(1).EntireRow.Dele
Sheets("Low Volume").Protect Sheets("DataSheet").Range(
Application.ScreenUpdating
End If
Next i
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It doesn't make the code more robust BUT it makes it incredibly faster, and easier on the eyes.
So yes, most often a good idea.
Thomas
So yes, most often a good idea.
Thomas
ASKER