Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Use a macro to merge cells in a column that are the same

Hi,

I posted earlier today but I have another related question. I have data
like this:

column A: column b:
red 1
red 2
red 4
blue 12
blue 7
green 9

I need a macro to merge the cells in column A where they have the same value
so instead i would get:

column A: column b:
red 1
2
4
blue 12
7
green 9

Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Use a macro to merge cells in a column that are the same

Don't do it!

Merged cells cause nothing but trouble--try filtering/sorting/charting with
merged cells and you'll see.

If all you want to do is hide those values so it looks pretty, then Debra
Dalgleish shows how:
http://www.contextures.com/xlCondFor...html#Duplicate

Josh Craig wrote:

Hi,

I posted earlier today but I have another related question. I have data
like this:

column A: column b:
red 1
red 2
red 4
blue 12
blue 7
green 9

I need a macro to merge the cells in column A where they have the same value
so instead i would get:

column A: column b:
red 1
2
4
blue 12
7
green 9

Any ideas?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Use a macro to merge cells in a column that are the same

I just finished writing a script to sort a sheet that contains a
column of merged cells. The very last step is to merge the cells
in column A, similar to what you want to do. However, the format
of my data is different from that of yours. Instead of repeat
values in column A, mine has blanks.

Mine is like:

Column A

red
blank
blank
blue
blank
green

etc.

In my case, the very last cell in Column A may be empty. Thus, I
have to use Column B to determine the range of cells. Here is my
code. You are welcome to modify it to suit your needs.

For Each cell In Worksheets("sheet1").Range([b1],
[b65536].End(xlUp)).Cells


If cell.Offset(0, -1).Value < "" Then
' if the cell in column A is not empty, reset counters
iCount1 = cell.Row
iCount2 = 0
Else
iCount2 = iCount2 + 1
End If

If cell.Offset(1, -1).Value < "" Then
Range(ActiveSheet.Cells(iCount1, 1),
ActiveSheet.Cells(iCount1 + iCount2, 1)).Select
Selection.Merge
End If

Next cell

Range(ActiveSheet.Cells(iCount1, 1),
ActiveSheet.Cells(iCount1 + iCount2, 1)).Select
Selection.Merge



Josh Craig wrote:
Hi,

I posted earlier today but I have another related question. I have data
like this:

column A: column b:
red 1
red 2
red 4
blue 12
blue 7
green 9

I need a macro to merge the cells in column A where they have the same value
so instead i would get:

column A: column b:
red 1
2
4
blue 12
7
green 9

Any ideas?

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
Merge the same group of cells down a column quickly Rich F Excel Discussion (Misc queries) 9 February 12th 10 02:30 PM
Merge Cells depending on another column sp123 Excel Programming 2 April 19th 06 09:13 PM
How do I merge two cells in a column AliWitt Excel Discussion (Misc queries) 1 February 9th 06 10:37 PM
How do I do a vertical merge of cells in a column? PAM Excel Discussion (Misc queries) 1 September 21st 05 06:51 PM
Merge Cells in a column Macro Mike G. Excel Programming 1 May 18th 04 05:34 PM


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