Concatenate data in columns - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Concatenate data in columns (/showthread.php?tid=5262) |
Concatenate data in columns - Qomplainerz - 07-27-2023 Example: Sub ConcatenateColumns() Dim lastRow As Long Dim i As Long 'Find the last row with data in column A lastRow = Cells(Rows.Count, "A").End(xlUp).Row 'Loop through each row and concatenate values from columns A and B For i = 1 To lastRow Cells(i, "C").Value = Cells(i, "A").Value & " " & Cells(i, "B").Value Next i End Sub Explanation: The code defines a subroutine named ConcatenateColumns. It declares variables for the last row with data (lastRow) and a loop counter (i). The lastRow variable is determined using Cells(Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A. The For loop iterates through each row from 1 to lastRow. In each iteration, the values from columns A and B are concatenated with a space (" ") in between, and the result is placed in column C using Cells(i, "C").Value. |