Adding all data into 1 cell from a row ignoring blanks and adding title before whats in non blank cells

scottyyboyy

New Member
Joined
Feb 2, 2015
Messages
41
Hi All,

I have searched all over the net and cant find the answer.

I have a spreadsheets with hundreds of thousands of rows and hundreds of columns, I need to pull out the data that's in a row and add all into 1 cell but where it finds data in a row i need it to take the title name to the word it finds in the row.

hope this makes sense please see below

emp no.Found datafirstnamelast nameagesexaddress 1address 2 Postcodedob

1
dave smith 22 wheel rd b22 2bbdavesmith22wheel rdb22 2nn
2scott 22 m 33 drive rd b22 2nn 19/02/1988
scott22m33 drive rdb22 2nn19/02/1988
3james bob m 22 b22 2nn 20/03/1957jamesbobm22b22 2nn20/03/1957


<tbody>
</tbody>


the green text is what i need but this is for 100,000 rows and goes to like column VZ ish.

Thanks in advance if someone can help me
Scott
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try
Code:
Dim cl As Range
For Each cl In Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
   cl.Value = Application.Trim(Join(Application.Index(cl.Offset(, 1).Resize(, 600).Value, 1, 0), " "))
Next cl
 
Upvote 0
Try
Code:
Dim cl As Range
For Each cl In Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
   cl.Value = Application.Trim(Join(Application.Index(cl.Offset(, 1).Resize(, 600).Value, 1, 0), " "))
Next cl


Hi,

Thanks for the reply this hasnt worked just comes up to save a macro in a module, dont know if im doing something wrong.
 
Upvote 0
Oops, forgot the start & end lines.
Code:
Sub scottyyboyy()
Dim cl As Range
For Each cl In Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
   cl.Value = Application.Trim(Join(Application.Index(cl.Offset(, 1).Resize(, 600).Value, 1, 0), " "))
Next cl
End Sub
 
Upvote 0
Oops, forgot the start & end lines.
Code:
Sub scottyyboyy()
Dim cl As Range
For Each cl In Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
   cl.Value = Application.Trim(Join(Application.Index(cl.Offset(, 1).Resize(, 600).Value, 1, 0), " "))
Next cl
End Sub

Hi Bud,

That is pulling the data from the row but i need it to take the title from row 1 where it finds data and add the title name before the data if finds.

hope this makes sense.

Regards
 
Upvote 0
Hi All,

I have searched all over the net and cant find the answer.

I have a spreadsheets with hundreds of thousands of rows and hundreds of columns, I need to pull out the data that's in a row and add all into 1 cell but where it finds data in a row i need it to take the title name to the word it finds in the row.

hope this makes sense please see below

emp no.Found datafirstnamelast nameagesexaddress 1address 2Postcodedob
1first name dave last name smith adress 1 22 address 2 wheel rd postcode b22 2bbdavesmith22wheel rdb22 2nn
2first name scott age 22 sex m address 233 drive rd postcode b22 2nn dob 19/02/1988scott22m33 drive rdb22 2nn19/02/1988
3first name james surname bob sex m address 1 22 postcode b22 2nn
dob 20/03/1957
jamesbobm22b22 2nn20/03/1957

<tbody>
</tbody>


the green text is what i need but this is for 100,000 rows and goes to like column VZ ish.

Thanks in advance if someone can help me
Scott

sorry i wrote the table incorrect please see updated my apologies
 
Upvote 0
If your data goes over to column VZ then you are likely going to hit problems with the length of string.
 
Upvote 0
Try
Code:
Sub scottyyboyy()
   Dim Ary As Variant
   Dim r As Long, c As Long
   Dim Tmp As String
   
   Ary = ActiveSheet.UsedRange.Value2
   For r = 2 To UBound(Ary)
      For c = 2 To UBound(Ary, 2)
         If Ary(r, c) <> "" Then
            If Tmp = "" Then Tmp = Ary(1, c) & " " & Ary(r, c) Else Tmp = Tmp & " " & Ary(1, c) & " " & Ary(r, c)
         End If
      Next c
      Debug.Print Len(Tmp)
      Ary(r, 1) = Tmp
      Tmp = ""
   Next r
   Range("A1").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
End Sub
But with 100,000 rows & 600 columns, it may well fail.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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