ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Merge various cells value in one row into one cell (https://www.excelbanter.com/excel-programming/416247-merge-various-cells-value-one-row-into-one-cell.html)

K[_2_]

Merge various cells value in one row into one cell
 
Hi all, I have data in my sheet (see below)
A B C D E………col
xx 01 02 06 07
zz 55 90 22 78
tt 15 02 05 09
ss 66 58 02 04
aa 18 20 10 03

I want macro which should combine each row cells value from coloum B
to E and put result in coloum F something like this (see below)
A B C D E F……col
xx 01 02 06 07 01-02-06-07
zz 55 90 22 78 55-90-22-78
tt 15 02 05 09 15-02-05-09
ss 66 58 02 04 66-58-02-04
aa 18 20 10 03 18-20-10-03

macro should put result in column F down to last value cell in column
A and macro should make sure that those values in cells which have
zero on the start like 01 or 02 when they will get combine by macro
they should stay in same format like "01-02" instead of "1-2". I hope
I was able to explain my question. Can any friend can help me in this.

Don Guillett

Merge various cells value in one row into one cell
 
Try this
Sub putcolstogetherinonecell()
Columns("f").ClearContents
For i = 2 To Cells(Rows.Count, "a").End(xlUp).Row
ms = ""
lc = Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To lc
ms = ms & "-" & Cells(i, j)
Next j
Cells(i, lc + 1) = Right(ms, Len(ms) - 1)
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"K" wrote in message
...
Hi all, I have data in my sheet (see below)
A B C D E………col
xx 01 02 06 07
zz 55 90 22 78
tt 15 02 05 09
ss 66 58 02 04
aa 18 20 10 03

I want macro which should combine each row cells value from coloum B
to E and put result in coloum F something like this (see below)
A B C D E F……col
xx 01 02 06 07 01-02-06-07
zz 55 90 22 78 55-90-22-78
tt 15 02 05 09 15-02-05-09
ss 66 58 02 04 66-58-02-04
aa 18 20 10 03 18-20-10-03

macro should put result in column F down to last value cell in column
A and macro should make sure that those values in cells which have
zero on the start like 01 or 02 when they will get combine by macro
they should stay in same format like "01-02" instead of "1-2". I hope
I was able to explain my question. Can any friend can help me in this.


K[_2_]

Merge various cells value in one row into one cell
 
On Aug 28, 10:33*pm, "Don Guillett" wrote:
Try this
Sub putcolstogetherinonecell()
Columns("f").ClearContents
For i = 2 To Cells(Rows.Count, "a").End(xlUp).Row
ms = ""
lc = Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To lc
ms = ms & "-" & Cells(i, j)
Next j
Cells(i, lc + 1) = Right(ms, Len(ms) - 1)
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"K" wrote in message

...
Hi all, *I have data in my sheet (see below)
* * A * * * *B * * * *C * * * D * * * E………col
* * xx * * * 01 * * *02 * * *06 * * * 07
* * zz * * * 55 * * *90 * * *22 * * * 78
* * tt * * * *15 * * * 02 * * *05 * * * 09
* * ss * * * 66 * * *58 * * *02 * * * 04
* * aa * * * 18 * * *20 * * *10 * * * 03

I want macro which should combine each row cells value from coloum B
to E and put result in coloum F something like this (see below)
* * A * * * *B * * * * *C * * * *D * * * *E * * * * * * F……col
* * xx * * * 01 * * * *02 * * * 06 * * * 07 * * * 01-02-06-07
* * zz * * * 55 * * * *90 * * * 22 * * * 78 * * * 55-90-22-78
* * tt * * * *15 * * * *02 * * * 05 * * * 09 * * * 15-02-05-09
* * ss * * * 66 * * * *58 * * * 02 * * * 04 * * * 66-58-02-04
* * aa * * * 18 * * * *20 * * * 10 * * * 03 * * * 18-20-10-03

macro should put result in column F down to last value cell in column
A and macro should make sure that those values in cells which have
zero on the start like 01 or 02 when they will get combine by macro
they should stay in same format like "01-02" instead of "1-2". *I hope
I was able to explain my question. Can any friend can help me in this.


Thanks Don it works perfect

Don Guillett

Merge various cells value in one row into one cell
 
Glad to help.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"K" wrote in message
...
On Aug 28, 10:33 pm, "Don Guillett" wrote:
Try this
Sub putcolstogetherinonecell()
Columns("f").ClearContents
For i = 2 To Cells(Rows.Count, "a").End(xlUp).Row
ms = ""
lc = Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To lc
ms = ms & "-" & Cells(i, j)
Next j
Cells(i, lc + 1) = Right(ms, Len(ms) - 1)
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"K" wrote in message

...
Hi all, I have data in my sheet (see below)
A B C D E………col
xx 01 02 06 07
zz 55 90 22 78
tt 15 02 05 09
ss 66 58 02 04
aa 18 20 10 03

I want macro which should combine each row cells value from coloum B
to E and put result in coloum F something like this (see below)
A B C D E F……col
xx 01 02 06 07 01-02-06-07
zz 55 90 22 78 55-90-22-78
tt 15 02 05 09 15-02-05-09
ss 66 58 02 04 66-58-02-04
aa 18 20 10 03 18-20-10-03

macro should put result in column F down to last value cell in column
A and macro should make sure that those values in cells which have
zero on the start like 01 or 02 when they will get combine by macro
they should stay in same format like "01-02" instead of "1-2". I hope
I was able to explain my question. Can any friend can help me in this.


Thanks Don it works perfect



All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com