vba to request a password for multiply dropdown list entries

DC195

New Member
Joined
Aug 17, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a vba code found on a previous thread which adds passwords to a drop down list, (Link to original post is included below). The vba works really well with my project with the drop down on sheet 1 and the passwords on sheet 2. Can this vba be used to handle multiply drop downs on sheet 1 sourcing from the same data on sheet 2 ??

I've tried to adapt the vba code myself but have very limited skills when coding and no surprise nothing but errors.

Any help would be greatly appreciated.


fig03.PNG
fig01.PNG
fig02.PNG
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Here's the vba in text if anybody wants a play.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rDV As Range, rDVChoices As Range, rChanged As Range, rCell As Range
  Dim sPWord As String, sErrors As String
 
  On Error GoTo Cleanup
  Set rDV = Columns("C").SpecialCells(xlCellTypeAllValidation)
  Set rChanged = Intersect(Target, rDV)
  If Not rChanged Is Nothing Then
    Application.EnableEvents = False
    With Sheets("Sheet2")
      Set rDVChoices = .Range("A1", .Range("A1").End(xlDown))
    End With
    For Each rCell In rChanged
      If Len(rCell.Value) > 0 Then
        sPWord = InputBox(Prompt:="Enter password for " & rCell.Value)
        If sPWord <> rDVChoices.Find(What:=rCell.Value, MatchCase:=False).Offset(, 1).Value Then
          sErrors = sErrors & vbLf & rCell.Value & "(" & rCell.Address(0, 0) & ")"
          rCell.ClearContents
        End If
      End If
    Next rCell
    If Len(sErrors) > 0 Then MsgBox "Incorrect password(s) for:" & sErrors, vbOKOnly
  End If
Cleanup:
  Application.EnableEvents = True
End Sub
 
Last edited by a moderator:
Upvote 0
Welcome to the MrExcel board!

Here's the vba in text if anybody wants a play.
That is much better than a picture of it but when posting vba code in the forum, please use the available code tags. It makes the code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
 
Upvote 0
Welcome to the MrExcel board!


That is much better than a picture of it but when posting vba code in the forum, please use the available code tags. It makes the code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
Thank you for your assistance and thank you for the welcome. I'm very much still learning the ropes.
 
Upvote 0
Not Sure if this the best way to resolve it but it works.


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rDV As Range, rDVChoices As Range, rChanged As Range, rCell As Range
  Dim sPWord As String, sErrors As String
  
  On Error GoTo Cleanup
  Set rDV = Columns("C").SpecialCells(xlCellTypeAllValidation)
  Set rChanged = Intersect(Target, rDV)
  If Not rChanged Is Nothing Then
    Application.EnableEvents = False
    With Sheets("Sheet2")
      Set rDVChoices = .Range("A1", .Range("A1").End(xlDown))
    End With
    For Each rCell In rChanged
      If Len(rCell.Value) > 0 Then
        sPWord = InputBox(Prompt:="Enter password for " & rCell.Value)
        If sPWord <> rDVChoices.Find(What:=rCell.Value, MatchCase:=False).Offset(, 1).Value Then
          sErrors = sErrors & vbLf & rCell.Value & "(" & rCell.Address(0, 0) & ")"
          rCell.ClearContents
        End If
      End If
    Next rCell
    If Len(sErrors) > 0 Then MsgBox "Incorrect password(s) for:" & sErrors, vbOKOnly
  End If
   On Error GoTo Cleanup
  Set rDV = Columns("E").SpecialCells(xlCellTypeAllValidation)
  Set rChanged = Intersect(Target, rDV)
  If Not rChanged Is Nothing Then
    Application.EnableEvents = False
    With Sheets("Sheet2")
      Set rDVChoices = .Range("A1", .Range("A1").End(xlDown))
    End With
    For Each rCell In rChanged
      If Len(rCell.Value) > 0 Then
        sPWord = InputBox(Prompt:="Enter password for " & rCell.Value)
        If sPWord <> rDVChoices.Find(What:=rCell.Value, MatchCase:=False).Offset(, 1).Value Then
          sErrors = sErrors & vbLf & rCell.Value & "(" & rCell.Address(0, 0) & ")"
          rCell.ClearContents
        End If
      End If
    Next rCell
    If Len(sErrors) > 0 Then MsgBox "Incorrect password(s) for:" & sErrors, vbOKOnly
  End If
  On Error GoTo Cleanup
  Set rDV = Columns("G").SpecialCells(xlCellTypeAllValidation)
  Set rChanged = Intersect(Target, rDV)
  If Not rChanged Is Nothing Then
    Application.EnableEvents = False
    With Sheets("Sheet2")
      Set rDVChoices = .Range("A1", .Range("A1").End(xlDown))
    End With
    For Each rCell In rChanged
      If Len(rCell.Value) > 0 Then
        sPWord = InputBox(Prompt:="Enter password for " & rCell.Value)
        If sPWord <> rDVChoices.Find(What:=rCell.Value, MatchCase:=False).Offset(, 1).Value Then
          sErrors = sErrors & vbLf & rCell.Value & "(" & rCell.Address(0, 0) & ")"
          rCell.ClearContents
        End If
      End If
    Next rCell
    If Len(sErrors) > 0 Then MsgBox "Incorrect password(s) for:" & sErrors, vbOKOnly
  End If
  Set rDV = Columns("I").SpecialCells(xlCellTypeAllValidation)
  Set rChanged = Intersect(Target, rDV)
  If Not rChanged Is Nothing Then
    Application.EnableEvents = False
    With Sheets("Sheet2")
      Set rDVChoices = .Range("A1", .Range("A1").End(xlDown))
    End With
    For Each rCell In rChanged
      If Len(rCell.Value) > 0 Then
        sPWord = InputBox(Prompt:="Enter password for " & rCell.Value)
        If sPWord <> rDVChoices.Find(What:=rCell.Value, MatchCase:=False).Offset(, 1).Value Then
          sErrors = sErrors & vbLf & rCell.Value & "(" & rCell.Address(0, 0) & ")"
          rCell.ClearContents
        End If
      End If
    Next rCell
    If Len(sErrors) > 0 Then MsgBox "Incorrect password(s) for:" & sErrors, vbOKOnly
  End If
Cleanup:
  Application.EnableEvents = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top