Excel VBA - Concatenate Module for Multiple Lines

Reqless

New Member
Joined
Mar 11, 2019
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi all. I am new to excel VBA and I am trying to create a module that will concatenate multiple lines.

Here is an example of data from the excel workbook:

MEEhzep.jpg


Once the macro is executed, I would like the result to look like this:

2YdzKkl.jpg




Any information would greatly appreciated. Thank you in advanced to anyone willing to contribute.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this:
Code:
Sub Combine_Values()
'Modified 3/11/2019 1:24:47 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
    Cells(i, 1).Value = Cells(i, 1).Value & " " & Cells(i, 2).Value & " " & Cells(i, 3).Value
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you have a long list, this may be quicker

Code:
Sub MM1()
    With Range("A1", Range("A" & Rows.Count).End(xlUp))
        .Value = Evaluate(.Address & "& "" "" & " & .Offset(, 1).Address & " & "" "" &  " & .Offset(, 2).Address)
        .Offset(, 1).Clear
        .Offset(, 2).Clear
    End With
End Sub
 
Upvote 0
Wow, that worked perfect. Thank you!

I have one more problem that I am hoping to find a solution to. Sorry for not posting within the original question!

It is similar to the original question, but different. For this example, the module will concatenate all data from columns B, C & D beginning with cells B2, C2, and D2 and ending with cells B200, C200, and D200. :

jqy4gj8
Q9G4lQZ.jpg
 
Upvote 0
Same question really, just the ranges change !!
Code:
Sub MM1()
    With Range("B2:B200")
        .Value = Evaluate(.Address & "& "" "" & " & .Offset(, 1).Address & " & "" "" &  " & .Offset(, 2).Address)
        .Offset(, 1).Clear
        .Offset(, 2).Clear
    End With
End Sub
 
Upvote 0
Michael - this worked flawlessly. I really appreciate your help, thank you!
 
Upvote 0
Glad to help....so what do you now do with 2 blank columns ??
 
Upvote 0
I leave it blank or I could remove the column, I guess it technically doesn't make a difference. Once the macro is ran (along side some other macros) the .csv file is uploaded to some software that arranges the data based on the column. When the software hits a blank column, it will proceed forward until it reaches a column containing data. At least that is my understanding of how the software analyzes the .csv file!
 
Upvote 0
Ok, but if you need to remove the blank cols, use...

Code:
Sub MM1()
    With Range("B2:B200")
        .Value = Evaluate(.Address & "& "" "" & " & .Offset(, 1).Address & " & "" "" &  " & .Offset(, 2).Address)
        .Offset(, 1).Clear
        .Offset(, 2).Clear
    End With
Range("C:D").EntireColumn.Delete
End Sub
 
Upvote 0
Okay great. Appreciate that. This will be good to have just in case.

Is it possible to combine multiple macros to execute as one process in line order?
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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