Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concatenate data in columns
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy data to another worksheet Qomplainerz 0 243 07-27-2023, 11:24 AM
Last Post: Qomplainerz
  Loop through columns and clear contents Qomplainerz 0 242 07-27-2023, 11:21 AM
Last Post: Qomplainerz
  Create a pivot table based on data in a worksheet with VBA Qomplainerz 0 262 07-27-2023, 09:48 AM
Last Post: Qomplainerz
  Filter data in a worksheet Qomplainerz 0 247 07-27-2023, 09:46 AM
Last Post: Qomplainerz
  Create a chart from data with VBA Qomplainerz 0 251 07-27-2023, 09:44 AM
Last Post: Qomplainerz
  Sort data in a range with VBA Qomplainerz 0 229 07-27-2023, 09:43 AM
Last Post: Qomplainerz
  Insert a new row and fill it with data in VBA Qomplainerz 0 207 07-27-2023, 09:11 AM
Last Post: Qomplainerz
  Add data validation to a cell with VBA Qomplainerz 0 232 07-27-2023, 09:10 AM
Last Post: Qomplainerz
  Copy data from one workbook to another with VBA Qomplainerz 0 218 07-27-2023, 08:02 AM
Last Post: Qomplainerz
  Pasting data with VBA Qomplainerz 0 195 07-27-2023, 06:33 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 2 Guest(s)