buckwheat4948
New Member
- Joined
- Jun 10, 2011
- Messages
- 14
I use the following code, supplied by Alphafrog to create a validation list.
Is it possible to use it to also sort the same rows the validation list is building from when the user clicks an item in the validation list? maybe using the formula2?
Dim strList As String, vList As Variant
Dim i As Long, j As Long
'Uniques
For Each cell In Range("A11:A30")
If cell.Value <> "" Then
If InStr(1, strList, cell.Value & ",", 1) = 0 Then strList = strList & cell.Value & ","
End If
Next cell
strList = Left(strList, Len(strList) - 1)
'Sort
vList = Split(strList, ",")
For i = 0 To UBound(vList)
For j = i To UBound(vList)
If LCase(vList(j)) < LCase(vList(i)) Then
strList = vList(i)
vList(i) = vList(j)
vList(j) = strList
End If
Next j
Next i
strList = vList(0)
For i = 1 To UBound(vList)
strList = strList & "," & vList(i)
Next i
Application.ScreenUpdating = False
With Range("A5").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=strList
.IgnoreBlank = True
.InCellDropdown = True
End With
Range("A6").Formula = "=IF(A5="""","""",COUNTIF(A11:A30,A5))"
Application.ScreenUpdating = True
Thanks!
Is it possible to use it to also sort the same rows the validation list is building from when the user clicks an item in the validation list? maybe using the formula2?
Dim strList As String, vList As Variant
Dim i As Long, j As Long
'Uniques
For Each cell In Range("A11:A30")
If cell.Value <> "" Then
If InStr(1, strList, cell.Value & ",", 1) = 0 Then strList = strList & cell.Value & ","
End If
Next cell
strList = Left(strList, Len(strList) - 1)
'Sort
vList = Split(strList, ",")
For i = 0 To UBound(vList)
For j = i To UBound(vList)
If LCase(vList(j)) < LCase(vList(i)) Then
strList = vList(i)
vList(i) = vList(j)
vList(j) = strList
End If
Next j
Next i
strList = vList(0)
For i = 1 To UBound(vList)
strList = strList & "," & vList(i)
Next i
Application.ScreenUpdating = False
With Range("A5").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=strList
.IgnoreBlank = True
.InCellDropdown = True
End With
Range("A6").Formula = "=IF(A5="""","""",COUNTIF(A11:A30,A5))"
Application.ScreenUpdating = True
Thanks!