Merge four columns into one cell.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings,
I'm trying to merge data in four columns ("F:I"). This will begin at Row 2 and go down to the last row in column F that has data. I got a basic VBA where I can get one row to merge. I just need it to include all rows that has data in Column F beginning on Row 2. Finally I need to Merge cells F across to I. Here is the formula that I managed to get one row to cooperate.

VBA Code:
Sub Merge()
    Dim lr As Long, i As Long
    lr = Range("F" & Rows.Count).End(xlDown).Row
        For i = 2 To lr
      Range("F" & i) = Range("F" & i).Text & Range("G" & i).Text & Range("H" & i).Text & Range("I" & i).Text
        End
    Next i
   End Sub

Below is an example of a row columns ("F:I"). The end result would be EB175010500002AXXX. Once they are combine I simply need to merge the cells across but begin on Row 1.

Merge Columns.JPG


Thank you,
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi, Please confirm the output expected if the sheet has below data:

06Feb2022.xlsm
EFGHIJ
1Column FColumn GColumn HColumn I
2F1G1H1I1
3F2G2H2I2
4F3G3H3I3
5
6
7
8
9
Sheet1
 
Upvote 0
Hi, Please confirm the output expected if the sheet has below data:

06Feb2022.xlsm
EFGHIJ
1Column FColumn GColumn HColumn I
2F1G1H1I1
3F2G2H2I2
4F3G3H3I3
5
6
7
8
9
Sheet1
I am trying to use a VBA not a formula bar. In this case the result for Column F2 would be F1G1H1I1. Then those rows would be merged into 1. The same thing would occur for all subsequent rows down to the last row where data is in column F.

Thank you,
 
Upvote 0
Greetings,
I'm trying to merge data in four columns ("F:I"). This will begin at Row 2 and go down to the last row in column F that has data. I got a basic VBA where I can get one row to merge. I just need it to include all rows that has data in Column F beginning on Row 2. Finally I need to Merge cells F across to I. Here is the formula that I managed to get one row to cooperate.

VBA Code:
Sub Merge()
    Dim lr As Long, i As Long
    lr = Range("F" & Rows.Count).End(xlDown).Row
        For i = 2 To lr
      Range("F" & i) = Range("F" & i).Text & Range("G" & i).Text & Range("H" & i).Text & Range("I" & i).Text
        End
    Next i
   End Sub

Below is an example of a row columns ("F:I"). The end result would be EB175010500002AXXX. Once they are combine I simply need to merge the cells across but begin on Row 1.

View attachment 57104

Thank you,
I was able to sort it out for the most part I think. I am going with this Macro
VBA Code:
Sub Concat_Columns()
Dim WS As Worksheet
Set WS = ActiveSheet
'find last row
LastRow = WS.Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
Dim result As String
For i = 2 To LastRow
    For j = 6 To 9
        If WS.Cells(i, j) <> "" Then
            If result <> "" Then
                result = result & WS.Cells(i, j).Text
            Else
                result = result & WS.Cells(i, j).Text
            End If
        End If
    Next j
    WS.Cells(i, 6) = result
    result = ""
Next i

End Sub
It does concat those four columns now I just need to delete the contents for columns 8:9 then merge 7:9

Thank you
 
Upvote 0
Solution
Hi,

To merge further (2nd row of each column) and to delete columns 7 to 9, you can use below code:

VBA Code:
    With WS
        .Cells(2, 6) = .Cells(2, 6) & .Cells(2, 7) & .Cells(2, 8) & .Cells(2, 9)
        .Range("G:I").Delete
    End With
 
Upvote 0
Hi,

To merge further (2nd row of each column) and to delete columns 7 to 9, you can use below code:

VBA Code:
    With WS
        .Cells(2, 6) = .Cells(2, 6) & .Cells(2, 7) & .Cells(2, 8) & .Cells(2, 9)
        .Range("G:I").Delete
    End With
Thank you very much indeed.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top