ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Merge Cells (https://www.excelbanter.com/excel-programming/281136-merge-cells.html)

Pete[_14_]

Merge Cells
 
I wish to merge all empty cells in a selection with the first non
empty cell above retaining that value e.g.

Smith
<empty
<empty
Jones
Bloggs
<empty

Smith)
)Merged
)
Jones
Bloggs)
)Merged

and so on...

any ideas?

Pete

Tom Ogilvy

Merge Cells
 
Sub MergeCells()
Dim rng As Range, cell As Range, ar As Range
Set rng = Selection.SpecialCells(xlBlanks)
For Each ar In rng.Areas
Set cell = ar.Offset(-1, 0).Resize(ar.Rows.Count + 1)
cell.Merge
Next
End Sub


Special cells is restricted to the usedrange, so make sure the cells at the
bottom in the selection are included in the usedrange.

--
Regards,
Tom Ogilvy



"Pete" wrote in message
m...
I wish to merge all empty cells in a selection with the first non
empty cell above retaining that value e.g.

Smith
<empty
<empty
Jones
Bloggs
<empty

Smith)
)Merged
)
Jones
Bloggs)
)Merged

and so on...

any ideas?

Pete





All times are GMT +1. The time now is 05:08 AM.

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