RE: Excel Row/Column Merge
- From: Billy Liddel <BillyLiddel@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 9 Jun 2007 13:12:01 -0700
I was given 15 separate sheets with group lists, some of the people onHi
group 1 also take part in up to four other groups.
My spreadsheet is set up as follows
Column A contains first name
Column B Surname
Column C Section
Then Columns D - S my various groups
So Tom Jones may have appear on rows 1 - 5 with one entry in each of
columns D F G K M
You can do this with a macro. I can't think how to do this in one go yet but
this macro will add to the person first line in stages so keep running it
until the the number of changes stays constant. You'll be told this.
Sub t()
Dim i As Long, nr As Long, col As Integer, nc As Integer
Dim c, d As String, tmp, count As Long, inf
Range("A1").Select
nr = Range("A1").CurrentRegion.Rows.count
nc = Range("A1").CurrentRegion.Columns.count
count = 0
'copy data to top row of each person
For i = 2 To nr
tmp = i
c = Cells(i, 1) & Cells(i, 2) & Cells(i, 3)
d = Cells(i + 1, 1) & Cells(i + 1, 2) & Cells(i + 1, 3)
If c = d Then
For j = 4 To nc
If IsEmpty(Cells(tmp, j)) Then
Cells(tmp, j) = Cells(i + 1, j)
count = count + 1
End If
Next j
End If
Next i
inf = MsgBox("Changes Made: " & count, vbDefaultButton1, "Changes made to
sheet")
End Sub
When you are happy use the next sub to delete the dupilcate rows. Only once
will do.
Sub DelDupes()
Dim i As Long, nr As Long, col As Integer, nc As Integer
Dim c, d As String, tmp
Range("A1").Select
nr = Range("A1").CurrentRegion.Rows.count
nc = Range("A1").CurrentRegion.Columns.count
'copy data to top row of each person
For i = nr To 2 Step -1
tmp = i
c = Cells(i, 1) & Cells(i, 2) & Cells(i, 3)
d = Cells(i - 1, 1) & Cells(i - 1, 2) & Cells(i - 1, 3)
If c = d Then
Range(Cells(i, 1), Cells(i, nc)).Delete
End If
Next i
End Sub
OPen the VB Editor (ALT + F11), >Insert >Module and copy the code into the
Module. the code will work on the active sheet in the workbook. Place the
cursor into Sub T and press F5 to run the code.
Do not run the DelDupes until you are happy with the results. Perhaps you
can copy the workbook and use this.
Regards
Peter
.
- Follow-Ups:
- Re: Excel Row/Column Merge
- From: rition
- Re: Excel Row/Column Merge
- References:
- Excel Row/Column Merge
- From: rition
- Excel Row/Column Merge
- Prev by Date: Re: help with formula please
- Next by Date: Re: Excel Row/Column Merge
- Previous by thread: Excel Row/Column Merge
- Next by thread: Re: Excel Row/Column Merge
- Index(es):
Relevant Pages
|