In this article, we will create a macro to combine text from two consecutive columns to a single column.
Raw data consists of First name and Last name, which we want to merge into a single column.
IntRow = Cells(Rows.Count, 1).End(xlUp).Row
The above code is used to get row number of the last cell.
Cells(i, 1) = Cells(i, 1) & " " & Cells(i, 2)
The above code concatenates values from cell in column 1 and column 2.
The above code is used to delete the second column.
Please follow below for the code
Option Explicit Sub CombiningData() 'Declaring variables Dim i As Integer, IntRow As Long 'Disabling screen updates Application.ScreenUpdating = False 'Getting row number of last cell IntRow = Cells(Rows.Count, 1).End(xlUp).Row 'Looping from 13th row to last row For i = 13 To IntRow 'Concatenating the value of two consecutive cells Cells(i, 1) = Cells(i, 1) & " " & Cells(i, 2) Next 'Assigning value to cell A12 Range("A12") = "Name" 'Deleting second column Columns(2).Delete 'Auto adjusting the size of cells in columns Columns.AutoFit 'Enabling screen updates Application.ScreenUpdating = True End Sub
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at firstname.lastname@example.org
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.