FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,368
- Office Version
- 365
- 2016
- Platform
- Windows
Hello All,
I found this macro below to help concatenate values from the first table into the second table. This is a relatively small sample of the original data, and due to the fact a UDF is volatile, of course the sheet runs a little slow.
Is there any type of alternative that might work but yet with a little more speed?
I found this macro below to help concatenate values from the first table into the second table. This is a relatively small sample of the original data, and due to the fact a UDF is volatile, of course the sheet runs a little slow.
Is there any type of alternative that might work but yet with a little more speed?
Order ID | SP Name |
105-22-N45 | Laura Callahan |
108-6-N17 | Janet Leverling |
102-14-F81 | Margaret Peacock |
103-25-F62 | Robert King |
106-12-N66 | Steven Buchanan |
103-14-N28 | Nancy Davolio |
105-21-F44 | Andrew Fuller |
109-26-N77 | Michael Suyama |
102-15-N56 | Anne Dodsworth |
108-6-N17 | Cisneros Gilberto |
102-14-F81 | Cooper Tyrese |
103-25-F62 | Dudley Cooper |
106-12-N66 | Ball Parker |
103-14-N28 | Barry Milo |
103-25-F62 | Phillips Bronson |
106-12-N66 | Weber Gage |
103-14-N28 | Nolan Mike |
106-12-N66 | Moore Jaquan |
103-14-N28 | Mcdowell Cesar |
103-14-N28 | Zimmerman Colby |
Order ID | Names |
105-22-N45 | Laura Callahan |
108-6-N17 | Janet Leverling / Cisneros Gilberto |
102-14-F81 | Margaret Peacock / Cooper Tyrese |
103-25-F62 | Robert King / Dudley Cooper / Phillips Bronson |
106-12-N66 | Steven Buchanan / Ball Parker / Weber Gage / Moore Jaquan |
103-14-N28 | Nancy Davolio / Barry Milo / Nolan Mike / Mcdowell Cesar / Zimmerman Colby |
105-21-F44 | Andrew Fuller |
109-26-N77 | Michael Suyama |
102-15-N56 | Anne Dodsworth |
VBA Code:
Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, _
ConcatenateRange As Range, Optional Separator As String = ",") As Variant
Dim i As Long
Dim strResult As String
On Error GoTo ErrHandler
If CriteriaRange.Count <> ConcatenateRange.Count Then
ConcatenateIf = CVErr(xlErrRef)
Exit Function
End If
For i = 1 To CriteriaRange.Count
If CriteriaRange.Cells(i).Value = Condition Then
If ConcatenateRange.Cells(i).Value <> "" Then
strResult = strResult & Separator & ConcatenateRange.Cells(i).Value
End If
End If
Next i
If strResult <> "" Then
strResult = Mid(strResult, Len(Separator) + 1)
End If
ConcatenateIf = strResult
Exit Function
ErrHandler:
ConcatenateIf = CVErr(xlErrValue)
End Function