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 cell text repeats, move the adjacent column to the same row

In the first column I have a student number, the second column the book
title. In the next row the same student number, with a different title, and
so on until I get to the next student number and a new set of book titles the
student has checked out. Is there a way using visual basic where the one
unique student number displays with all of the titles for that student in the
same row?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default if cell text repeats, move the adjacent column to the same row

This example assumes that the original data is on Sheet1 and the revised
format will be entered in Sheet2:

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

--
Gary''s Student - gsnu200772


"ILoveMyCorgi" wrote:

In the first column I have a student number, the second column the book
title. In the next row the same student number, with a different title, and
so on until I get to the next student number and a new set of book titles the
student has checked out. Is there a way using visual basic where the one
unique student number displays with all of the titles for that student in the
same row?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default if cell text repeats, move the adjacent column to the same row

Here is some code to do it

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 2 Step -1

If .Cells(i, "A").Value = .Cells(i - 1, "A").Value Then

.Cells(i, "B").Resize(, 100).Copy .Cells(i - 1, "C")
.Rows(i).Delete
End If
Next i
End With

End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"ILoveMyCorgi" wrote in message
...
In the first column I have a student number, the second column the book
title. In the next row the same student number, with a different title,
and
so on until I get to the next student number and a new set of book titles
the
student has checked out. Is there a way using visual basic where the one
unique student number displays with all of the titles for that student in
the
same row?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default if cell text repeats, move the adjacent column to the same row

THANK YOU!!! You just made my life a little easier... Now I can incorporate
the output with another list for a longer row of data I plan to use later.
Thanks a million! susan

"Gary''s Student" wrote:

This example assumes that the original data is on Sheet1 and the revised
format will be entered in Sheet2:

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

--
Gary''s Student - gsnu200772


"ILoveMyCorgi" wrote:

In the first column I have a student number, the second column the book
title. In the next row the same student number, with a different title, and
so on until I get to the next student number and a new set of book titles the
student has checked out. Is there a way using visual basic where the one
unique student number displays with all of the titles for that student in the
same row?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default if cell text repeats, move the adjacent column to the same row

You have no idea how much this has helped me... I appreciate learning the two
different ways of accomplishing this task... thanks again, Bob. Susan

"Bob Phillips" wrote:

Here is some code to do it

Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 2 Step -1

If .Cells(i, "A").Value = .Cells(i - 1, "A").Value Then

.Cells(i, "B").Resize(, 100).Copy .Cells(i - 1, "C")
.Rows(i).Delete
End If
Next i
End With

End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"ILoveMyCorgi" wrote in message
...
In the first column I have a student number, the second column the book
title. In the next row the same student number, with a different title,
and
so on until I get to the next student number and a new set of book titles
the
student has checked out. Is there a way using visual basic where the one
unique student number displays with all of the titles for that student in
the
same row?






  #6   Report Post  
Posted to microsoft.public.excel.programming
MJD MJD is offline
external usenet poster
 
Posts: 5
Default if cell text repeats, move the adjacent column to the same row

I've been trying to use this macro and it keeps crashing my system. I'm sure
I'm doing it wrong because I'm not very advanced with Visual Basic. I have
some data that I've got to find a way to organize.

Column A: Last Name
Column B: First Name
Column C: ID number

These are the rows that are being duplicated that I'd like to put into one
row where the columns of data are in D - M.

I've got about 6,000 rows of data that should be about 3,000 when all is
said and done.

Any suggestions?

"Gary''s Student" wrote:

This example assumes that the original data is on Sheet1 and the revised
format will be entered in Sheet2:

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

--
Gary''s Student - gsnu200772


"ILoveMyCorgi" wrote:

In the first column I have a student number, the second column the book
title. In the next row the same student number, with a different title, and
so on until I get to the next student number and a new set of book titles the
student has checked out. Is there a way using visual basic where the one
unique student number displays with all of the titles for that student in the
same row?

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
Use VB to move to adjacent cell Bstice Excel Programming 4 June 16th 07 01:20 AM
move to adjacent cell with panes frozen Aaron Excel Discussion (Misc queries) 1 October 5th 06 10:45 AM
How to Automatically Move Cell datato adjacent cell.. cardingtr Excel Discussion (Misc queries) 1 October 17th 05 03:59 AM
tab does not move to adjacent cell in excel Karen Boyd Excel Discussion (Misc queries) 1 September 21st 05 07:09 PM
excel tab key to move to right adjacent cell dwillie Excel Discussion (Misc queries) 2 January 26th 05 08:01 PM


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

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

About Us

"It's about Microsoft Excel"