Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
if student number repeats move all data for that number on to same
In the first column I have a student number, the second column a currency
value, the third column a date, and the third column contains comments. The next row may contain the same student number, with a different amount and comment, and so on until I get to the next student number and a new set amounts and comments. Is there a way using visual basic where the one unique student number displays with all of the currency amounts and corresponding comments for that student in the same row? I am trying to do a merge and need all the data on one row. I have the VB below, but it doesn't work! Thanks for your help. Sub newlist() Set w1 = Sheets("Sheet1") Set w2 = Sheets("Sheet2") w2.Cells(1, 1).Value = w1.Cells(1, 1).Value w2.Cells(1, 2).Value = w1.Cells(1, 2).Value Ide = Cells(1, 1).Value w1.Activate n = Cells(Rows.Count, 1).End(xlUp).Row k = 3 kk = 1 For i = 2 To n If w1.Cells(i, 1).Value = Ide Then w2.Cells(kk, k).Value = w1.Cells(i, 2).Value k = k + 1 Else kk = kk + 1 k = 3 Ide = w1.Cells(i, 1).Value w2.Cells(kk, 1).Value = Ide w2.Cells(kk, 2).Value = w1.Cells(i, 2).Value End If Next End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
if student number repeats move all data for that number on to same
I am sorry... i deleted the third column [the date] -- I have a total of
three columns. Thanks. "ILoveMyCorgi" wrote: In the first column I have a student number, the second column a currency value, the third column a date, and the third column contains comments. The next row may contain the same student number, with a different amount and comment, and so on until I get to the next student number and a new set amounts and comments. Is there a way using visual basic where the one unique student number displays with all of the currency amounts and corresponding comments for that student in the same row? I am trying to do a merge and need all the data on one row. I have the VB below, but it doesn't work! Thanks for your help. Sub newlist() Set w1 = Sheets("Sheet1") Set w2 = Sheets("Sheet2") w2.Cells(1, 1).Value = w1.Cells(1, 1).Value w2.Cells(1, 2).Value = w1.Cells(1, 2).Value Ide = Cells(1, 1).Value w1.Activate n = Cells(Rows.Count, 1).End(xlUp).Row k = 3 kk = 1 For i = 2 To n If w1.Cells(i, 1).Value = Ide Then w2.Cells(kk, k).Value = w1.Cells(i, 2).Value k = k + 1 Else kk = kk + 1 k = 3 Ide = w1.Cells(i, 1).Value w2.Cells(kk, 1).Value = Ide w2.Cells(kk, 2).Value = w1.Cells(i, 2).Value End If Next End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Finding Minimum but if same number repeats in the range, then find | Excel Discussion (Misc queries) | |||
Random number generation - with no repeats | Excel Discussion (Misc queries) | |||
frequency a number repeats in a column | Excel Worksheet Functions | |||
How can I count the number of times a letter repeats in a string? | Excel Worksheet Functions | |||
How can I count the number of repeats in a list of data? | Excel Discussion (Misc queries) |