Tim Hanson
Member
The concatenations macro has work well for me but in a new project I have to dynamically generate multiple Sheets with multiple columns of varying number
The data looks like this:
The code uses
which does not select the whole column range due to the blank rows
I have tried but found no way to replace "CurrentRegion" with a different method
I am hoping someone here will know how to do this
Thanks
The data looks like this:
Code:
Col A Col B Col C
aa ee
mm
nn
uu
aa mm
The code uses
Code:
With Cells(1).CurrentRegion
I have tried but found no way to replace "CurrentRegion" with a different method
I am hoping someone here will know how to do this
Thanks
Code:
Sub ConCat()
Dim rng As Range, r As Range, i As Long
On Error Resume Next
'This is just an example range each sheet is different
Set rng = Range("B1,A1,C1")
On Error GoTo 0
If rng Is Nothing Then Exit Sub
With Cells(1).CurrentRegion
ReDim a(1 To .Rows.Count, 1 To 1)
a(1, 1) = "Concat"
For i = 2 To .Rows.Count
For Each r In rng
If .Cells(i, r.Column) <> "" Then
a(i, 1) = a(i, 1) & IIf(a(i, 1) = "", "", "|") & .Cells(i, r.Column).Value
End If
Next
Next
With .Offset(, .Columns.Count).Resize(, 1)
.Value = a
End With
End With
End Sub