BritsBlitz
New Member
- Joined
- Jan 10, 2014
- Messages
- 34
- Office Version
- 365
- Platform
- Windows
I have the following Array and I'm trying to use TextJoin and Filter in VBA to combine the elements of the array and place it in one cell
For instance, for Farmer John, the output should be Apples, Oranges, Peaches, Grapes, Lemons, Strawberries
I'm using a FOR loop to step through each of the array entries and TextJoin to combine the text for each array line together, but would like to combine the text from multiple array lines together if they match.
Hardcoding it I did the following:
This code will produce "Apples, Orange, Peaches" but when the next condition of Farmer John = True comes around, it overwrites it with "Grapes, Lemons, Strawberries" How do I add it all together instead of overwriting it? Using a formula, I can use the FILTER function, but not sure how to apply that in VBA.
Farmer John | Apples | Oranges | Peaches |
Farmer Mike | Pears | Bananas | Kiwi |
Farmer John | Grapes | Lemons | Strawberries |
Farmer Steve | Guavas | Nectarines | Dragon Fruit |
For instance, for Farmer John, the output should be Apples, Oranges, Peaches, Grapes, Lemons, Strawberries
I'm using a FOR loop to step through each of the array entries and TextJoin to combine the text for each array line together, but would like to combine the text from multiple array lines together if they match.
Hardcoding it I did the following:
VBA Code:
For ArrayStart = 1 to 4
If FarmerArray(ArrayStart, 1) = "Farmer John" Then
Worksheets("Farmers").Cells(1,1).Value = Worksheetfunction.TextJoin(", ", True, FarmerArray(ArrayStart,2), FarmerArray(ArrayStart,3), FarmerArray(ArrayStart,4))
End If
Next ArrayStart
This code will produce "Apples, Orange, Peaches" but when the next condition of Farmer John = True comes around, it overwrites it with "Grapes, Lemons, Strawberries" How do I add it all together instead of overwriting it? Using a formula, I can use the FILTER function, but not sure how to apply that in VBA.