combining related data into one row

Reset

Board Regular
Joined
Apr 16, 2010
Messages
227
This is what I am trying to do. I have a data where the first column is the serial number and that row is its data. The serial number can be in multiple rows. I want to find each instance, capture two pieces of data (a date and value), and put it all on one row in another sheet. For example
a, 1/9/11, 1
a, 1/17/11, 2
a, 1/28/11, 3
becomes
a, 1/9/11, 1, 1/17/11, 2, 1/28/11, 3
(commas denote next cell)

My code so far:
a = Application.WorksheetFunction.CountA(Columns(1))
i = 2
s = 2
linea: 'reit point
Sheets("Sheet1").Select
For x = i To 25
c = 1
If Cells(x + 1, 1) <> Cells(x, 1) Then GoTo line1
c = c + 1
s = x
Next x
line1: 'Jump out
MsgBox (c)
sn = Cells(x, 1)
ReDim d(c) As Date
ReDim v(c) As Long
g = 0
For y = (x - c) + 1 To s + 1
g = g + 1
d(g) = Cells(y, 8)
v(g) = Cells(y, 21)

Next y
Sheets("Sheet3").Select
b = Application.WorksheetFunction.CountA(Columns(1)) + 1
Cells(b, 1) = sn
g = 0
For y = 2 To c * 2 Step 2
g = g + 1
Cells(b, y) = d(g)
Cells(b, y + 1) = v(g)
Next y
i = i + c
c = 0
If i < 25 Then GoTo linea

But the results are the last of the duplicates repeated for the number of times the serial number shows up. Can anyone see the error?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
If you haven't fixed your problem yet, here is the fix.

Your code shows:
Rich (BB code):
....
For x = i To 25
    c = 1
....

Move c=1 outside the For Loop. It needs to be
Rich (BB code):
....
c = 1
For x = i To 25
....
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

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