Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Minimum but if same number repeats in the range, then find MIK Excel Discussion (Misc queries) 1 January 9th 09 03:13 AM
Random number generation - with no repeats Ryan Excel Discussion (Misc queries) 3 May 8th 08 03:40 PM
frequency a number repeats in a column Ken Excel Worksheet Functions 5 March 8th 07 03:12 AM
How can I count the number of times a letter repeats in a string? Wiley Excel Worksheet Functions 3 May 11th 06 06:53 PM
How can I count the number of repeats in a list of data? SouthCarolina Excel Discussion (Misc queries) 7 March 7th 06 10:03 PM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"