PC Review


Reply
Thread Tools Rate Thread

Concat rows -

 
 
nmpb
Guest
Posts: n/a
 
      15th Jan 2009
Hi
I need a program to be able to concate all the rows in B until the cell in
column A is
not blank. would also want a separator between them.
ie row C1 = 000034001570;000034001571;000034001582;000034001589
C6 = 000034032303

A B
1 000034001570 000034001570
2 000034001571
3 000034001582
4 000034001589
5 000034001589
6 000034032303 000034032303
7 000034066598 000034066598
8 000034017214 000034017214
9 000034017215
10 000034019302
11 000034019303

The issue is that I have a sheet of over 40,000 rows, also I have noticed
that I have duplicates in the column B, which will have to be excluded.
Its been a while since I've done any programming so any help appreciated

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      15th Jan 2009
Sub CombineRows()

RowCount = 1
Data = ""
Do While Range("B" & RowCount) <> ""
If Data = "" Then
Data = Range("B" & RowCount)
Else
Data = Data & ";" & Range("B" & RowCount)
End If

If Range("A" & (RowCount + 1)) <> "" Then
Range("B" & RowCount) = Data
Data = ""
RowCount = RowCount + 1
Else
Rows(RowCount).Delete
End If
Loop
End Sub


"nmpb" wrote:

> Hi
> I need a program to be able to concate all the rows in B until the cell in
> column A is
> not blank. would also want a separator between them.
> ie row C1 = 000034001570;000034001571;000034001582;000034001589
> C6 = 000034032303
>
> A B
> 1 000034001570 000034001570
> 2 000034001571
> 3 000034001582
> 4 000034001589
> 5 000034001589
> 6 000034032303 000034032303
> 7 000034066598 000034066598
> 8 000034017214 000034017214
> 9 000034017215
> 10 000034019302
> 11 000034019303
>
> The issue is that I have a sheet of over 40,000 rows, also I have noticed
> that I have duplicates in the column B, which will have to be excluded.
> Its been a while since I've done any programming so any help appreciated
>

 
Reply With Quote
 
nmpb
Guest
Posts: n/a
 
      15th Jan 2009
Thank you for such a quick response. It works.
Can you change it so that the result appears in column C please so it does
not overwrite the data in column B.


"Joel" wrote:

> Sub CombineRows()
>
> RowCount = 1
> Data = ""
> Do While Range("B" & RowCount) <> ""
> If Data = "" Then
> Data = Range("B" & RowCount)
> Else
> Data = Data & ";" & Range("B" & RowCount)
> End If
>
> If Range("A" & (RowCount + 1)) <> "" Then
> Range("B" & RowCount) = Data
> Data = ""
> RowCount = RowCount + 1
> Else
> Rows(RowCount).Delete
> End If
> Loop
> End Sub
>
>
> "nmpb" wrote:
>
> > Hi
> > I need a program to be able to concate all the rows in B until the cell in
> > column A is
> > not blank. would also want a separator between them.
> > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > C6 = 000034032303
> >
> > A B
> > 1 000034001570 000034001570
> > 2 000034001571
> > 3 000034001582
> > 4 000034001589
> > 5 000034001589
> > 6 000034032303 000034032303
> > 7 000034066598 000034066598
> > 8 000034017214 000034017214
> > 9 000034017215
> > 10 000034019302
> > 11 000034019303
> >
> > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > that I have duplicates in the column B, which will have to be excluded.
> > Its been a while since I've done any programming so any help appreciated
> >

 
Reply With Quote
 
nmpb
Guest
Posts: n/a
 
      15th Jan 2009
could you also exclude the duplicates in column B.

Thank you

"nmpb" wrote:

> Thank you for such a quick response. It works.
> Can you change it so that the result appears in column C please so it does
> not overwrite the data in column B.
>
>
> "Joel" wrote:
>
> > Sub CombineRows()
> >
> > RowCount = 1
> > Data = ""
> > Do While Range("B" & RowCount) <> ""
> > If Data = "" Then
> > Data = Range("B" & RowCount)
> > Else
> > Data = Data & ";" & Range("B" & RowCount)
> > End If
> >
> > If Range("A" & (RowCount + 1)) <> "" Then
> > Range("B" & RowCount) = Data
> > Data = ""
> > RowCount = RowCount + 1
> > Else
> > Rows(RowCount).Delete
> > End If
> > Loop
> > End Sub
> >
> >
> > "nmpb" wrote:
> >
> > > Hi
> > > I need a program to be able to concate all the rows in B until the cell in
> > > column A is
> > > not blank. would also want a separator between them.
> > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > C6 = 000034032303
> > >
> > > A B
> > > 1 000034001570 000034001570
> > > 2 000034001571
> > > 3 000034001582
> > > 4 000034001589
> > > 5 000034001589
> > > 6 000034032303 000034032303
> > > 7 000034066598 000034066598
> > > 8 000034017214 000034017214
> > > 9 000034017215
> > > 10 000034019302
> > > 11 000034019303
> > >
> > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > that I have duplicates in the column B, which will have to be excluded.
> > > Its been a while since I've done any programming so any help appreciated
> > >

 
Reply With Quote
 
GB
Guest
Posts: n/a
 
      15th Jan 2009
If you change the line in the second if statement that reads:
Range("B" & RowCount) = Data
To
Range("C" & RowCount) = Data

Then your "answer" will be stored in Column C instead of column B.


"nmpb" wrote:

> Thank you for such a quick response. It works.
> Can you change it so that the result appears in column C please so it does
> not overwrite the data in column B.
>
>
> "Joel" wrote:
>
> > Sub CombineRows()
> >
> > RowCount = 1
> > Data = ""
> > Do While Range("B" & RowCount) <> ""
> > If Data = "" Then
> > Data = Range("B" & RowCount)
> > Else
> > Data = Data & ";" & Range("B" & RowCount)
> > End If
> >
> > If Range("A" & (RowCount + 1)) <> "" Then
> > Range("B" & RowCount) = Data
> > Data = ""
> > RowCount = RowCount + 1
> > Else
> > Rows(RowCount).Delete
> > End If
> > Loop
> > End Sub
> >
> >
> > "nmpb" wrote:
> >
> > > Hi
> > > I need a program to be able to concate all the rows in B until the cell in
> > > column A is
> > > not blank. would also want a separator between them.
> > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > C6 = 000034032303
> > >
> > > A B
> > > 1 000034001570 000034001570
> > > 2 000034001571
> > > 3 000034001582
> > > 4 000034001589
> > > 5 000034001589
> > > 6 000034032303 000034032303
> > > 7 000034066598 000034066598
> > > 8 000034017214 000034017214
> > > 9 000034017215
> > > 10 000034019302
> > > 11 000034019303
> > >
> > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > that I have duplicates in the column B, which will have to be excluded.
> > > Its been a while since I've done any programming so any help appreciated
> > >

 
Reply With Quote
 
nmpb
Guest
Posts: n/a
 
      15th Jan 2009
Thank you - now I just need to exclude the duplicates

"GB" wrote:

> If you change the line in the second if statement that reads:
> Range("B" & RowCount) = Data
> To
> Range("C" & RowCount) = Data
>
> Then your "answer" will be stored in Column C instead of column B.
>
>
> "nmpb" wrote:
>
> > Thank you for such a quick response. It works.
> > Can you change it so that the result appears in column C please so it does
> > not overwrite the data in column B.
> >
> >
> > "Joel" wrote:
> >
> > > Sub CombineRows()
> > >
> > > RowCount = 1
> > > Data = ""
> > > Do While Range("B" & RowCount) <> ""
> > > If Data = "" Then
> > > Data = Range("B" & RowCount)
> > > Else
> > > Data = Data & ";" & Range("B" & RowCount)
> > > End If
> > >
> > > If Range("A" & (RowCount + 1)) <> "" Then
> > > Range("B" & RowCount) = Data
> > > Data = ""
> > > RowCount = RowCount + 1
> > > Else
> > > Rows(RowCount).Delete
> > > End If
> > > Loop
> > > End Sub
> > >
> > >
> > > "nmpb" wrote:
> > >
> > > > Hi
> > > > I need a program to be able to concate all the rows in B until the cell in
> > > > column A is
> > > > not blank. would also want a separator between them.
> > > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > > C6 = 000034032303
> > > >
> > > > A B
> > > > 1 000034001570 000034001570
> > > > 2 000034001571
> > > > 3 000034001582
> > > > 4 000034001589
> > > > 5 000034001589
> > > > 6 000034032303 000034032303
> > > > 7 000034066598 000034066598
> > > > 8 000034017214 000034017214
> > > > 9 000034017215
> > > > 10 000034019302
> > > > 11 000034019303
> > > >
> > > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > > that I have duplicates in the column B, which will have to be excluded.
> > > > Its been a while since I've done any programming so any help appreciated
> > > >

 
Reply With Quote
 
GB
Guest
Posts: n/a
 
      15th Jan 2009
This could be a tough question to answer without more information from you.

If I assume that you only want to capture the first instance of the data in
column B the first time (instead of the last time) that it is used, then
within the first if statement, just after the else statement, change this to
perform a search of the data from row 1 to the row before rowcount by using
something like a selection.find operation to find the value of the current
"Range". If the value is not found then run the

Data = Data & ";" ...etc.

if the data is found then do nothing.

So the following will combine the rows into a single cell and maintain your
original data integrity, placing the result (data not previously found in
column B) in the row that contains data in column A.

Option Explicit

Public Sub testCombineRows()

Dim RowCount As Long
Dim Data As String
Dim FirstRowData As Long

RowCount = 1
Data = ""
FirstRowData = RowCount
Do While Range("B" & RowCount) <> ""
If RowCount > 1 Then
Range("B1:B" & RowCount - 1).Select
Else
'At the first row, but still want to add it.
End If

If RowCount = 1 Then
Data = Range("B" & RowCount)
ElseIf Selection.Find(Range("B" & RowCount)) Is Nothing And RowCount >
1 And Data = "" Then
Data = Range("B" & RowCount)
ElseIf Selection.Find(Range("B" & RowCount)) Is Nothing Then
Data = Data & ";" & Range("B" & RowCount)
Else
'The data has been found before
End If

If Range("A" & (RowCount + 1)) <> "" Or Range("B" & (RowCount + 1)) = ""
Then
Range("C" & FirstRowData) = Data
Data = ""
RowCount = RowCount + 1
FirstRowData = RowCount
Else
RowCount = RowCount + 1
'Rows(RowCount).Delete
End If
Loop


Worked for me, hope it does what you wanted. (I commented out the
Rows(RowCount).Delete line so that no data would not be deleted.
End Sub


"nmpb" wrote:

> could you also exclude the duplicates in column B.
>
> Thank you
>
> "nmpb" wrote:
>
> > Thank you for such a quick response. It works.
> > Can you change it so that the result appears in column C please so it does
> > not overwrite the data in column B.
> >
> >
> > "Joel" wrote:
> >
> > > Sub CombineRows()
> > >
> > > RowCount = 1
> > > Data = ""
> > > Do While Range("B" & RowCount) <> ""
> > > If Data = "" Then
> > > Data = Range("B" & RowCount)
> > > Else
> > > Data = Data & ";" & Range("B" & RowCount)
> > > End If
> > >
> > > If Range("A" & (RowCount + 1)) <> "" Then
> > > Range("B" & RowCount) = Data
> > > Data = ""
> > > RowCount = RowCount + 1
> > > Else
> > > Rows(RowCount).Delete
> > > End If
> > > Loop
> > > End Sub
> > >
> > >
> > > "nmpb" wrote:
> > >
> > > > Hi
> > > > I need a program to be able to concate all the rows in B until the cell in
> > > > column A is
> > > > not blank. would also want a separator between them.
> > > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > > C6 = 000034032303
> > > >
> > > > A B
> > > > 1 000034001570 000034001570
> > > > 2 000034001571
> > > > 3 000034001582
> > > > 4 000034001589
> > > > 5 000034001589
> > > > 6 000034032303 000034032303
> > > > 7 000034066598 000034066598
> > > > 8 000034017214 000034017214
> > > > 9 000034017215
> > > > 10 000034019302
> > > > 11 000034019303
> > > >
> > > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > > that I have duplicates in the column B, which will have to be excluded.
> > > > Its been a while since I've done any programming so any help appreciated
> > > >

 
Reply With Quote
 
GB
Guest
Posts: n/a
 
      15th Jan 2009
See thread above that asked the question about excluding duplicates.

"nmpb" wrote:

> Thank you - now I just need to exclude the duplicates
>
> "GB" wrote:
>
> > If you change the line in the second if statement that reads:
> > Range("B" & RowCount) = Data
> > To
> > Range("C" & RowCount) = Data
> >
> > Then your "answer" will be stored in Column C instead of column B.
> >
> >
> > "nmpb" wrote:
> >
> > > Thank you for such a quick response. It works.
> > > Can you change it so that the result appears in column C please so it does
> > > not overwrite the data in column B.
> > >
> > >
> > > "Joel" wrote:
> > >
> > > > Sub CombineRows()
> > > >
> > > > RowCount = 1
> > > > Data = ""
> > > > Do While Range("B" & RowCount) <> ""
> > > > If Data = "" Then
> > > > Data = Range("B" & RowCount)
> > > > Else
> > > > Data = Data & ";" & Range("B" & RowCount)
> > > > End If
> > > >
> > > > If Range("A" & (RowCount + 1)) <> "" Then
> > > > Range("B" & RowCount) = Data
> > > > Data = ""
> > > > RowCount = RowCount + 1
> > > > Else
> > > > Rows(RowCount).Delete
> > > > End If
> > > > Loop
> > > > End Sub
> > > >
> > > >
> > > > "nmpb" wrote:
> > > >
> > > > > Hi
> > > > > I need a program to be able to concate all the rows in B until the cell in
> > > > > column A is
> > > > > not blank. would also want a separator between them.
> > > > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > > > C6 = 000034032303
> > > > >
> > > > > A B
> > > > > 1 000034001570 000034001570
> > > > > 2 000034001571
> > > > > 3 000034001582
> > > > > 4 000034001589
> > > > > 5 000034001589
> > > > > 6 000034032303 000034032303
> > > > > 7 000034066598 000034066598
> > > > > 8 000034017214 000034017214
> > > > > 9 000034017215
> > > > > 10 000034019302
> > > > > 11 000034019303
> > > > >
> > > > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > > > that I have duplicates in the column B, which will have to be excluded.
> > > > > Its been a while since I've done any programming so any help appreciated
> > > > >

 
Reply With Quote
 
nmpb
Guest
Posts: n/a
 
      15th Jan 2009
Wow! GB - THANKS
I did not see this reply before I posted mine. I will test and let you know
the outcome.

"GB" wrote:

> This could be a tough question to answer without more information from you.
>
> If I assume that you only want to capture the first instance of the data in
> column B the first time (instead of the last time) that it is used, then
> within the first if statement, just after the else statement, change this to
> perform a search of the data from row 1 to the row before rowcount by using
> something like a selection.find operation to find the value of the current
> "Range". If the value is not found then run the
>
> Data = Data & ";" ...etc.
>
> if the data is found then do nothing.
>
> So the following will combine the rows into a single cell and maintain your
> original data integrity, placing the result (data not previously found in
> column B) in the row that contains data in column A.
>
> Option Explicit
>
> Public Sub testCombineRows()
>
> Dim RowCount As Long
> Dim Data As String
> Dim FirstRowData As Long
>
> RowCount = 1
> Data = ""
> FirstRowData = RowCount
> Do While Range("B" & RowCount) <> ""
> If RowCount > 1 Then
> Range("B1:B" & RowCount - 1).Select
> Else
> 'At the first row, but still want to add it.
> End If
>
> If RowCount = 1 Then
> Data = Range("B" & RowCount)
> ElseIf Selection.Find(Range("B" & RowCount)) Is Nothing And RowCount >
> 1 And Data = "" Then
> Data = Range("B" & RowCount)
> ElseIf Selection.Find(Range("B" & RowCount)) Is Nothing Then
> Data = Data & ";" & Range("B" & RowCount)
> Else
> 'The data has been found before
> End If
>
> If Range("A" & (RowCount + 1)) <> "" Or Range("B" & (RowCount + 1)) = ""
> Then
> Range("C" & FirstRowData) = Data
> Data = ""
> RowCount = RowCount + 1
> FirstRowData = RowCount
> Else
> RowCount = RowCount + 1
> 'Rows(RowCount).Delete
> End If
> Loop
>
>
> Worked for me, hope it does what you wanted. (I commented out the
> Rows(RowCount).Delete line so that no data would not be deleted.
> End Sub
>
>
> "nmpb" wrote:
>
> > could you also exclude the duplicates in column B.
> >
> > Thank you
> >
> > "nmpb" wrote:
> >
> > > Thank you for such a quick response. It works.
> > > Can you change it so that the result appears in column C please so it does
> > > not overwrite the data in column B.
> > >
> > >
> > > "Joel" wrote:
> > >
> > > > Sub CombineRows()
> > > >
> > > > RowCount = 1
> > > > Data = ""
> > > > Do While Range("B" & RowCount) <> ""
> > > > If Data = "" Then
> > > > Data = Range("B" & RowCount)
> > > > Else
> > > > Data = Data & ";" & Range("B" & RowCount)
> > > > End If
> > > >
> > > > If Range("A" & (RowCount + 1)) <> "" Then
> > > > Range("B" & RowCount) = Data
> > > > Data = ""
> > > > RowCount = RowCount + 1
> > > > Else
> > > > Rows(RowCount).Delete
> > > > End If
> > > > Loop
> > > > End Sub
> > > >
> > > >
> > > > "nmpb" wrote:
> > > >
> > > > > Hi
> > > > > I need a program to be able to concate all the rows in B until the cell in
> > > > > column A is
> > > > > not blank. would also want a separator between them.
> > > > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > > > C6 = 000034032303
> > > > >
> > > > > A B
> > > > > 1 000034001570 000034001570
> > > > > 2 000034001571
> > > > > 3 000034001582
> > > > > 4 000034001589
> > > > > 5 000034001589
> > > > > 6 000034032303 000034032303
> > > > > 7 000034066598 000034066598
> > > > > 8 000034017214 000034017214
> > > > > 9 000034017215
> > > > > 10 000034019302
> > > > > 11 000034019303
> > > > >
> > > > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > > > that I have duplicates in the column B, which will have to be excluded.
> > > > > Its been a while since I've done any programming so any help appreciated
> > > > >

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      15th Jan 2009
This code assumes the data in column B is in ascending order.

Sub CombineRows()

RowCount = 1
Data = ""
Do While Range("B" & RowCount) <> ""
NewData = Range("B" & RowCount)
If Data = "" Then
Data = NewData
Else
if NewData <> LastData then
Data = Data & ";" & NewData
End if
End If
LastData = NewData

If Range("A" & (RowCount + 1)) <> "" Then
Range("C" & RowCount) = Data
Data = ""
RowCount = RowCount + 1
Else
Rows(RowCount).Delete
End If
Loop
End Sub

"nmpb" wrote:

> Thank you for such a quick response. It works.
> Can you change it so that the result appears in column C please so it does
> not overwrite the data in column B.
>
>
> "Joel" wrote:
>
> > Sub CombineRows()
> >
> > RowCount = 1
> > Data = ""
> > Do While Range("B" & RowCount) <> ""
> > If Data = "" Then
> > Data = Range("B" & RowCount)
> > Else
> > Data = Data & ";" & Range("B" & RowCount)
> > End If
> >
> > If Range("A" & (RowCount + 1)) <> "" Then
> > Range("B" & RowCount) = Data
> > Data = ""
> > RowCount = RowCount + 1
> > Else
> > Rows(RowCount).Delete
> > End If
> > Loop
> > End Sub
> >
> >
> > "nmpb" wrote:
> >
> > > Hi
> > > I need a program to be able to concate all the rows in B until the cell in
> > > column A is
> > > not blank. would also want a separator between them.
> > > ie row C1 = 000034001570;000034001571;000034001582;000034001589
> > > C6 = 000034032303
> > >
> > > A B
> > > 1 000034001570 000034001570
> > > 2 000034001571
> > > 3 000034001582
> > > 4 000034001589
> > > 5 000034001589
> > > 6 000034032303 000034032303
> > > 7 000034066598 000034066598
> > > 8 000034017214 000034017214
> > > 9 000034017215
> > > 10 000034019302
> > > 11 000034019303
> > >
> > > The issue is that I have a sheet of over 40,000 rows, also I have noticed
> > > that I have duplicates in the column B, which will have to be excluded.
> > > Its been a while since I've done any programming so any help appreciated
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
concat rows nmpb Microsoft Excel Worksheet Functions 4 15th Jan 2009 10:50 AM
CONCAT fingermark@gmail.com Microsoft Access Queries 3 20th Jun 2006 09:18 PM
Concat in asp =?Utf-8?B?RmFybnp5?= Microsoft Frontpage 5 25th Mar 2006 09:14 AM
Concat different rows column into single row field troppfigo@excite.it Microsoft Access Queries 1 22nd Feb 2006 02:30 AM
Concat values in two or more rows based on id and eliminate duplicates italia Microsoft Excel Programming 2 19th Oct 2005 06:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.