Sorry, I am trying to get the output like this
IDNUM LASTNAME FIRSTNAME INSTITUTION (UP TO 4 INSTITUTIONS) COURSE (COURSE1, COURSE2 UPTO COURSE14) ADDRESS
123 Harris Jane ABC college WRS UNIVERSITY | MINOR SOCIOLOGY(course1 from ABC college) Religion & Modern Thought(course2 from ABC college) PSYCHOLOGY (course1 from WRS university) Nutrition (course2 from WRS) 164 Firefox RD
234 Smith John CBD UNVERSTIY |AESTHETIC PRINCIPLES & ELEMENTS INTRODUCTION TO VISUAL CULTURE 603 Parkway DR
"|" means the end of institution data.
I copied someone's macro to generate
123 Harris Jane ABC college WRS UNIVERSITY
234 Smith John CBD UNVERSTIY
I don't know how to go further for course and address.
Here is the Macro:
Sub Merge()
Dim bSame As Boolean
Dim iCol As Integer
Dim lRow As Long
Dim rData As Range, R As Range
Dim vDataLine() As Variant
Dim vKey(1 To 3) As Variant
Dim wsFr As Worksheet, wsTo As Worksheet
Set wsFr = Sheets("Sheet1")
Set wsTo = Sheets("Sheet2")
wsTo.Cells.ClearContents
Set rData = wsFr.Range("A2:A" & wsFr.Cells(Rows.Count, 1).End(xlUp).Row)
ReDim vDataLine(1 To 4)
For iCol = 1 To 4
vDataLine(iCol) = wsFr.Cells(1, iCol).Value
Next iCol
For Each R In rData
bSame = True
For iCol = 1 To 3
vKey(iCol) = R.Offset(0, iCol - 1).Value
If vKey(iCol) <> vDataLine(iCol) Then bSame = False
Next iCol
If bSame = False Then
lRow = lRow + 1
wsTo.Range(Cells(lRow, 1).Address, Cells(lRow, UBound(vDataLine)).Address) = vDataLine
ReDim vDataLine(1 To 3)
For iCol = 1 To 3
vDataLine(iCol) = vKey(iCol)
Next iCol
End If
iCol = UBound(vDataLine) + 1
ReDim Preserve vDataLine(1 To iCol)
vDataLine(iCol) = R.Offset(0, 3).Value
Next R
lRow = lRow + 1
wsTo.Range(Cells(lRow, 1).Address, Cells(lRow, UBound(vDataLine)).Address) = vDataLine
End Sub
|
|