Hi,
On the attached file, when a Value from Cell D1 is selected, it outputs corresponding values from Column E separated by commas..
All working as desired with this code -
Sub Conc()
Dim InputVal As String, R As Variant, Counter As Integer, NewVal(), C As Integer
InputVal = Range("D1").Value2
R = Range("A1").CurrentRegion
For Counter = LBound(R,1) To UBound(R,1)
If R(Counter, 1) = InputVal Then
C = C + 1
ReDim Preserve NewVal(1 To C)
NewVal(C) = R(Counter, 2)
End If
Next Counter
Range("E1").Value2 = InputVal & " " & Join(NewVal, ",")
End Sub
I would like to know If the code can be further optimized? For example better use of arrays, loops etc.
Bookmarks