john316swan
Board Regular
- Joined
- Oct 13, 2016
- Messages
- 66
- Office Version
- 2019
- Platform
- Windows
I have a pivot table with data:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Doc 1[/TD]
[TD]doc 2[/TD]
[TD]doc 3[/TD]
[TD]doc 4[/TD]
[TD]combine docs[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]1[/TD]
[TD][/TD]
[TD]Doc 1,Doc 3 (=combineDocs(A2:A4))[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[TD]Doc 2,Doc 3 (=combineDocs(B2:B4))[/TD]
[/TR]
</tbody>[/TABLE]
I am trying to write a function (combine docs) that combines all documents in 1 string
I found this code online that I modified but I can't figure out how to have the column header value displayed:
Thanks for your help!
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Doc 1[/TD]
[TD]doc 2[/TD]
[TD]doc 3[/TD]
[TD]doc 4[/TD]
[TD]combine docs[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]1[/TD]
[TD][/TD]
[TD]Doc 1,Doc 3 (=combineDocs(A2:A4))[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[TD]Doc 2,Doc 3 (=combineDocs(B2:B4))[/TD]
[/TR]
</tbody>[/TABLE]
I am trying to write a function (combine docs) that combines all documents in 1 string
I found this code online that I modified but I can't figure out how to have the column header value displayed:
Code:
Function combineDocs(workRng As Range, Optional Sign As String = ",") As String
Dim r As Range
Dim OutStr As String
For Each r In workRng
If r.Text <> "" Then
OutStr = OutStr & Cells(2, Left(r, 1)).Text & Sign 'note my column header is on row 2
End If
Next
combineDocs = Left(OutStr, Len(OutStr) - 1)
End Function
Thanks for your help!