The data I am working with contains blocks of cells in column C, with between 1-10 cells in them, that all have text in them. The blocks represent customer reviews. The last cell will always end with "(hide full review)".
I want to write a function that will move through the column and concatenate the cells together and then stop when it finds a cell that contains (hide full review) at end of it.
I found this function on mrexcel which almost works perfectly. The only problem it encounters is when reviews are only 1 line, it also concatenates the line after the blank cell.
I tried modifying the function with the bold VBA below, but I am still struggling to get it to run correctly.
Any Help would be appreciated!
Best,
Eric
I want to write a function that will move through the column and concatenate the cells together and then stop when it finds a cell that contains (hide full review) at end of it.
I found this function on mrexcel which almost works perfectly. The only problem it encounters is when reviews are only 1 line, it also concatenates the line after the blank cell.
Rich (BB code):
Function colconc(CellRef As Range, Delimiter As String)
Dim LoopVar As Long
Dim StartRow As Long
Dim EndRow As Long
Dim Concat As String
Dim Col As Long
Col = CellRef.Column
StartRow = CellRef.row
EndRow = CellRef.End(xlDown).row
Concat = ""
For LoopVar = StartRow To EndRow
Concat = Concat & Cells(LoopVar, Col).Value
If LoopVar <> EndRow Then Concat = Concat & Delimiter
Next LoopVar
colconc = Concat
End Function
I tried modifying the function with the bold VBA below, but I am still struggling to get it to run correctly.
Rich (BB code):
Function ColConcer(CellRef As Range, Delimiter As String)
Dim LoopVar As Long
Dim StartRow As Long
Dim EndRow As Long
Dim Concat As String
Dim Col As Long
Dim theendrow As Long
Dim txt As String
Dim c As Long
Col = CellRef.Column
Debug.Print Col
StartRow = CellRef.row
EndRow = CellRef.End(xlDown).row
For c = StartRow To EndRow
txt = Cells(c, 3).Value
If IsNumeric(InStr(1, txt, "(hide full review)")) = True Then
theendrow = Cells(LoopVar, Col)
End If
Next c
Concat = ""
For LoopVar = StartRow To theendrow
Concat = Concat & Cells(LoopVar, Col).Value
If LoopVar <> theendrow Then Concat = Concat & Delimiter
Next LoopVar
ColConcer = Concat
End Function
Any Help would be appreciated!
Best,
Eric
Last edited by a moderator: