LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Record Merge Macro


Hello,

I am trying to merge 3 columns to 2 in the following way:

itemID title details
00-10114 Three Love Songs Nelson Keyes page 20
00-10114 Prelude and Fugue II (C Minor) David Diamond page 36 C
00-10114 Mobile Leslie Bassett page 18
00-10114 Homage to Milhaud Lou Harrison page 17 G
00-10114 Medley (Campfire on the Ice) Ross Lee Finney page 7 G Major
00-10114 Four Piano Pieces Bruce Wise page 10
00-10145 Motions Paul Sheftel page 3 A Minor
00-10145 Position Shift Rock Paul Sheftel page 13 C Major
00-10145 Mad for That Triad Paul Sheftel page 5 C Major


You'll notice that the database has several titles for each line, eve
though they are all part of the same itemID.

I'd like to run a macro that combines the rows to columns using "," a
a separator, so the result looks like:

itemID title
00-10114 Three Love Songs (Nelson Keyes page 20), Prelude and Fugue I
(C Minor) (David Diamond page 36 C), etc.

with 3 columns converting to 2 columns (title & details being combine
with ", ") for every unique itemID.

I posted a similar request several years ago, actually, and kept th
macro which worked great then, but I believe the database was slightl
different -- it's not working now ;) Here's what I tried:

-----------
Sub MergeRecords()
Dim nRecords As Integer
Dim X As Integer

Range("A1").Select
nRecords = ActiveCell.CurrentRegion.Rows.Count

'First pass will combine cells in cols B & C
For X = 1 To nRecords - 1
ActiveCell.Offset(X, 1) _
= ActiveCell.Offset(X, 1) _
& "[" & ActiveCell.Offset(X, 2) _
& "]"
ActiveCell.Offset(X, 2) = ""
Next X

'Then combine Rows
For X = nRecords - 1 To 1 Step -1
If ActiveCell.Offset(X, 0) _
= ActiveCell.Offset(X - 1, 0) Then
ActiveCell.Offset(X - 1, 1) _
= ActiveCell.Offset(X - 1, 1) _
& ", " & _
ActiveCell.Offset(X, 1)
ActiveCell.Offset(X, 0).EntireRow.Delete
End If
Next X

'Then combine Cols A & B
nRecords = ActiveCell.CurrentRegion.Rows.Count

For X = 1 To nRecords - 1
ActiveCell.Offset(X, 0) _
= ActiveCell.Offset(X, 0) _
& " " _
& ActiveCell.Offset(X, 1)
ActiveCell.Offset(X, 1) = ""
Next X
End Sub
----------------------

Any suggestions (or an entirely new macro) would be greatl
appreciated!

Thanks so much!!

Joh

--
johngoodel
-----------------------------------------------------------------------
johngoodell's Profile: http://www.excelforum.com/member.php...fo&userid=2653
View this thread: http://www.excelforum.com/showthread.php?threadid=39800

 
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
Find double record and merge Chris Excel Worksheet Functions 4 March 6th 08 11:06 PM
Mail Merge <<Next Record sonicj Excel Discussion (Misc queries) 4 October 25th 07 12:34 AM
How to merge records into one record by customer's name? Newuser New Users to Excel 3 May 18th 05 04:49 AM
Different graphic for each record in mail merge document Alex St-Pierre Charts and Charting in Excel 1 May 4th 05 07:26 PM
Record Macro - Record custom user actions Sal[_4_] Excel Programming 1 December 23rd 04 03:18 PM


All times are GMT +1. The time now is 02:27 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"