Merge Cells / Keep Text for Unique Column 1 Cell Values? :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Merge Cells / Keep Text for Unique Column 1 Cell Values?
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

Whoa
Welcome to the Board


Joined: 19 Sep 2003
Posts: 5

Flag: Blank

Status: Offline

 Reply with quote  

Merge Cells / Keep Text for Unique Column 1 Cell Values?

I have a simple task that I can't figure out.

I have rows of data with two columns per row:

A C
A M
A Q
B R
B F
C D
C J

and I want to select those cells and have it change them to:

A C, M, Q
A
A
B R, F
B
C D,J
C

Column 1 is sorted. A,B,C are not the real values of my data but you get the idea. There might be 20 A rows, 30 B rows, etc. I want to process through them and concatenate the Column 2 values for every unique Column 1 value.

Could anybody help me with this coding? I keep trying and I keep failing.

Post Fri Sep 19, 2003 9:57 pm 
 View user's profile Send private message

Whoa
Welcome to the Board


Joined: 19 Sep 2003
Posts: 5

Flag: Blank

Status: Offline

 Reply with quote  

Re: Merge Cells / Keep Text for Unique Column 1 Cell Values?

HTML's treating multiple spaces as one messed things up a bit.

The idea is that I start with two columns of data and I end up with two columns of data. Only the values of cells in the second column change, either to blank or to a long string that is a concatenation of all the other second column cells associated with the same, identical cell 1 value.

Hope that makes sense.

Post Fri Sep 19, 2003 9:59 pm 
 View user's profile Send private message

just_jon
MrExcel MVP


Joined: 04 Sep 2002
Posts: 4007
Location: Huntsville AL
Flag: Blank

Status: Offline

 Reply with quote  

Re: Merge Cells / Keep Text for Unique Column 1 Cell Values?

Best I could come up with in the time alotted is

Microsoft Excel - Book1___Running: xl2000 : OS = Windows ME
(F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
=

A
B
C
D
1
ACC 
2
AMC,M 
3
AQC,M,QC,M,Q
4
BRR 
5
BFR,FR,F
6
CDD 
7
CJD,JD,J
Sheet1 

[HtmlMaker 2.40] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.


which really isn't very good... no testing beyong what you see...
_________________
just_jon
Book of the Month: I'm Not Really an MVP, I Just Play One on TV [j. jon, 2004]

Post Fri Sep 19, 2003 10:18 pm 
 View user's profile Send private message

Yogi Anand
MrExcel MVP


Joined: 13 Mar 2002
Posts: 5749
Location: Michigan USA

Status: Offline

 Reply with quote  

Re: Merge Cells / Keep Text for Unique Column 1 Cell Values?

Hi Whoa:

I had a bit of play with the following macro ...

code:

Sub yWhoa()
    CountNC = 0
    For j = 2 To 100
        K = j + CountNC - 1
        Cells(K, 1).Select
        If cels(K, 1) = "" Then Exit Sub
        Cells(ActiveCell.Row, 3) = Cells(ActiveCell.Row, 2)
        CountNC = WorksheetFunction.CountIf([a2:a8], ActiveCell): Debug.Print CountNC
        For i = 1 To CountNC - 1
            Cells(ActiveCell.Row, 3) = Cells(ActiveCell.Row, 3) & Cells(ActiveCell.Row + i, 2)
        Next i
    Next j
End Sub



to produce the following result ...

Microsoft Excel - y030919h2.xls___Running: xl97 : OS = Windows 98
(F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
=

A
B
C
D
1
Field1Field2ComboField 
2
ACCMQ 
3
AM  
4
AQ  
5
BR  
6
BFFD 
7
CDDJ 
8
CJ  
Sheet6 

[HtmlMaker 2.20] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.


I kept the integrity of the source data and produced the resulting concatenation in column C.

I hope this helps. If I have misunderstood the question -- my apologies!
_________________
Regards!
Yogi Anand

Post Fri Sep 19, 2003 10:47 pm 
 View user's profile Send private message

Whoa
Welcome to the Board


Joined: 19 Sep 2003
Posts: 5

Flag: Blank

Status: Offline

 Reply with quote  

Re: Merge Cells / Keep Text for Unique Column 1 Cell Values?

Thank you so much!

These solutions have really helped me and I've got it working now!

Post Sat Sep 20, 2003 11:04 am 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.