Advertisement
YasserKhalil2019

T4233_Data Validation List In Worksheet Change

Oct 28th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. https://excel-egy.com/forum/t4233
  2. ---------------------------------
  3.  
  4. Private Sub Worksheet_Change(ByVal Target As Range)
  5. Dim x, lr As Long
  6.  
  7. If Target.Cells.CountLarge > 1 Then Exit Sub
  8.  
  9. If Target.Address = "$B$1" Then
  10. x = Application.Match("احياء " & Target.Value, Rows(3), 0)
  11.  
  12. If Not IsError(x) Then
  13. With Range("D1").Validation
  14. .Delete
  15. lr = Application.Max(4, Cells(Rows.Count, x).End(xlUp).Row)
  16. If Cells(4, x).Value = "" Then Exit Sub
  17.  
  18. .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=" & Range(Cells(4, x), Cells(lr, x)).Address
  19. End With
  20. Else
  21. Range("D1").Validation.Delete
  22. End If
  23. End If
  24. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement