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 :eek:
 
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)
Column E</SPAN>Column F</SPAN>Column G (Concatenated text from macro)</SPAN>
Mr</SPAN>1</SPAN>Mr Excel</SPAN>
Excel</SPAN>2</SPAN>
Hi</SPAN>1</SPAN>Hi My Name Is</SPAN>
My </SPAN>2</SPAN>
Name</SPAN>3</SPAN>
Is</SPAN>4</SPAN>

<TBODY>
</TBODY>
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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
FIREFLY2012 You are the man!!! Thank you so very much can I do anything to reciprocate your help? Thanks again buddy :cool:
 
Upvote 0

Forum statistics

Threads
1,215,981
Messages
6,128,085
Members
449,418
Latest member
arm56

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