Hi
I was wondering if someone would be able to help me, please?
I've created two separate "buttons" for a spreadsheet that filters information viewable based on whether or not specific text has been used.
The code I've used to do this is:
Button one
Sub HURows2()
BeginRow = 13
EndRow = 128
ChkCol = 8
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = "Light" Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
End Sub
Button two
Sub HURows1()
BeginRow = 13
EndRow = 128
ChkCol = 8
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = "Master" Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
End Sub
I now want to make it so those two buttons are password protected and only those with the password can execute the macro. I've tried a variety of different codes and I've found one which kind of does what I want it to do, but not completely. This code is:
Private Sub CommandButton1_Click()
Dim password As Variant
password = Application.InputBox("Enter Password", "Protected Macro")
Select Case password
Case Is = False
'do nothing
Case Is = "SocialValue"
Sub HURows2()
BeginRow = 13
EndRow = 128
ChkCol = 8
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = "Light" Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
Case Else
MsgBox "Incorrect Password"
End Select
End Sub
The problem that I'm having with this is two-fold; the first is that it's erroring "Case Else outside Select Case"; if I add "Select Case password" above "Case Else", a box just pops up to say "Incorrect Password" but doesn't provide me with the opportunity to input a password.
Apologies for the really long post, but could someone please help me? I'm at my wit's end and not very experienced in doing VBA.
Thank you.
Bookmarks