Hi,
can anyone please update the code below? It is for dropdown menu, which cannot be overwritten with copy+paste.
This works perfectly, but sometimes the list is too long (over 255 characters) and once I close and open the file it is showing errors. I found the solution and it needs to be done through a range.
No matter how I try to change the code I get Syntax errors. Since I am complete beginner I can't figure out how to refer to a list in name manager.
Here is the code:
Can anyone please help? Thank you very much.
can anyone please update the code below? It is for dropdown menu, which cannot be overwritten with copy+paste.
This works perfectly, but sometimes the list is too long (over 255 characters) and once I close and open the file it is showing errors. I found the solution and it needs to be done through a range.
No matter how I try to change the code I get Syntax errors. Since I am complete beginner I can't figure out how to refer to a list in name manager.
Here is the code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Dim cell As Range
Dim dd As Variant
Dim i As Long
Dim mtch As Boolean
Dim msg As String
Dim myEntries As String
Set isect = Intersect(Range("B7:B600"), Target)
If Not isect Is Nothing Then
Application.EnableEvents = False
dd = Array("A", "B", "C", "D", "")
For Each cell In isect
mtch = False
For i = LBound(dd) To UBound(dd)
If cell.Value = dd(i) Then
mtch = True
Exit For
End If
Next i
If mtch = False Then
cell.ClearContents
msg = msg & cell.Address(0, 0) & ","
End If
Next cell
For i = LBound(dd) To UBound(dd)
myEntries = myEntries & dd(i) & ","
Next i
myEntries = Left(myEntries, Len(myEntries) - 1)
With Range("B7:B600").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=myEntries
' .IgnoreBlank = True
' .InCellDropdown = True
' .InputTitle = ""
' .ErrorTitle = ""
' .InputMessage = ""
' .ErrorMessage = ""
' .ShowInput = True
' .ShowError = True
End With
If Len(msg) > 0 Then
MsgBox "Invalid data in cells: " & vbCrLf & Left(msg, Len(msg) - 1), vbOKOnly, "Error"
End If
End If
Application.EnableEvents = True
End Sub
Can anyone please help? Thank you very much.