
Originally Posted by
tehneXus
When the list is created by vba it is possible:
Sub Macro1()
With Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Range("D4").Value
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
with the list created in A1 and the values in 1 cell comma separated in D4
The VBA function I use is the following.
Option Explicit
Public Function FindProd(TRange As Range, MatchWith As String)
Dim cell As Variant
Dim xString As Variant
For Each cell In TRange
If cell.Value = MatchWith Then
xString = xString & cell.Offset(0, 1).Value & ","
End If
Next cell
xString = Left(xString, (Len(xString) - 1))
'Checking for dups
Dim UniqueValues As New Collection
Dim x As Variant, Item As Variant
Dim Txt As Variant, ConcatValues As Variant
Dim i As Long
Txt = xString
'Txt = Application.Substitute((Range("A2").Value), " ", "")
x = Split(Txt, ",")
On Error Resume Next
For i = LBound(x) To UBound(x)
UniqueValues.Add x(i), CStr(x(i))
Next i
On Error GoTo 0
For Each Item In UniqueValues
ConcatValues = ConcatValues & "," & Item
Next Item
ConcatValues = Mid(ConcatValues, 2)
xString = ConcatValues
FindProd = xString
End Function
Of course, it isn't "clean" but it gets the job done for finding values of table then deleting duplicates.
Is it possible to alter it so it also allows me to create a validation list dynamically in the same row that the function is used? Example: If the function is used in B5, I want a validation list with the found data to be shown in C5.
Thank you!!!!!
Bookmarks