PDA

View Full Version : [SOLVED:] combining texts in a row in one cell macro



jecali
10-22-2024, 01:46 PM
Hello there

is there some steps that i can make to combine the text distributed 3 cells in one row, to be gathered in first column? and have it as a macro?
also would be great if that macro does that to all filled rows.
thanks, a bit new to this..:yes

Aussiebear
10-22-2024, 04:33 PM
Maybe something like this:


Sub ConcatenateCells()
Dim rng As Range
Dim cell1 As Range, cell2 As Range, cell3 As Range
Dim concatCell As Range
Dim i As Long
' Set the range containing the cells to be concatenated
Set rng = Range("A2:C100") ' Adjust the range as needed
' Specify the column where the concatenated result will be placed
Dim concatColumn As String
concatColumn = "D" ' Change to the desired column letter
' Loop through each row in the range
For i = 1 To rng.Rows.Count
Set cell1 = rng.Cells(i, 1) ' First cell
Set cell2 = rng.Cells(i, 2) ' Second cell
Set cell3 = rng.Cells(i, 3) ' Third cell
' Concatenate the values
Set concatCell = Cells(i, Columns(concatColumn).Column)
concatCell.Value = cell1.Value & cell2.Value & cell3.Value
Next i
MsgBox "Concatenation completed successfully."
End Sub

arnelgp
10-22-2024, 09:59 PM
to concatenate rows from column B to C and put in column A, you write this formula in column A:

=B1&C1&D1

then drag it to the last row you want to apply the formula.

jecali
10-23-2024, 12:08 PM
Thank you ! it worked

jecali
10-23-2024, 12:09 PM
also this is a good one and combining this with relative cell selection and recording made it dynamic