Please help me with VB Code

I

ILoveMyCorgi

I need to place all of a student’s data on one row. In the first column I
have a student number [this number identifies the student], the second column
contains a currency value, the third column contains comments. The next row
may contain the same student number, with a different amount and a different
comment, or the next row could go on to the next student number and a new
amount and comments for that student. Is there a way using visual basic where
the one unique student number displays with all of the data for that student
number on the same row? The spreadsheet is sorted by student number. 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 because I have one additional
column! Not sure what I need to do to modify this code to make it work. I
am real lame when it comes to this... Please help me. Thanks for your help.
Susan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top