ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Use a macro to merge cells in a column that are the same (https://www.excelbanter.com/excel-programming/366386-use-macro-merge-cells-column-same.html)

Josh Craig

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?


Dave Peterson

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

John Smith

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?



All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com