Help with writing a macro to concatenate data

acrasherkid

New Member
Joined
Feb 12, 2013
Messages
11
Hi Guys,

First of all I have been a huge fan of this forum for years veyr good work thanks a bunch!

My problem is I have data in the same format each month and need to concatenate each row with a comma between them. The data I need to concatenate is in column E and the the number of rows are denoted in column F, this never changes. In column F the first row may state 1 the second row 2 etc until the text is finished for example in this case 7. Then it will start again 1 to however many there are. I need to create a macro that looks in column f to see how many rows of data should be concatenated in column e.

Example

Column E Column F
Mr 1
Excel 2
Hi 1
My 2
Name 3
Is 4

I think you see the point! Rather than manually concatenate each row I need the macro to put the concatenated text in Column G.

Please help :eeek:
 
The Macro is working and is amazing thanks Firefly!!!

One small little thing though if poss? I have more data to the left related to the rows. Each concatenated line is shown under one another. Would it be possible to have the text display next to the first 1 rather than in a list as I need to take the concatenated text and place this at the first instance (Where F = 1) then delete al other numbers other than 1 leaving me with the full text.

So for example ( the numbers should be under F)
[TABLE="class: cms_table"]
<TBODY>[TR]
[TD]Column E</SPAN>[/TD]
[TD]Column F</SPAN>[/TD]
[TD]Column G (Concatenated text from macro)</SPAN>[/TD]
[/TR]
[TR]
[TD]Mr</SPAN>[/TD]
[TD="align: right"]1</SPAN>[/TD]
[TD]Mr Excel</SPAN>[/TD]
[/TR]
[TR]
[TD]Excel</SPAN>[/TD]
[TD="align: right"]2</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Hi</SPAN>[/TD]
[TD="align: right"]1</SPAN>[/TD]
[TD]Hi My Name Is</SPAN>[/TD]
[/TR]
[TR]
[TD]My </SPAN>[/TD]
[TD="align: right"]2</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Name</SPAN>[/TD]
[TD="align: right"]3</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Is</SPAN>[/TD]
[TD="align: right"]4</SPAN>[/TD]
[/TR]
</TBODY>[/TABLE]
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Sure - try this:

Code:
Sub Conc_Data()
Dim vIn, vOut
Dim i As Long, j As Long

vIn = Range("E1:F" & Cells(Rows.Count, "F").End(xlUp).Row).Value

ReDim vOut(1 To UBound(vIn, 1), 1 To 1)

j = 0
For i = 1 To UBound(vIn, 1)
    If vIn(i, 2) = 1 Then
        j = i
        vOut(j, 1) = vIn(i, 1)
    Else
        vOut(j, 1) = vOut(j, 1) & " " & vIn(i, 1)
    End If
Next i

Range("G1").Resize(UBound(vOut, 1)).Value = vOut
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top