Merge cells in multiple selected areas Column by Column


/ Published in: Visual Basic
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Sub MergeCxC()
  2. '-- Merge cells in multiple selected areas Column by Column ---
  3. ' limited to the usedrange (Ctrl+End)
  4. ' D.McRitchie, 2002-05-31 in merge.htm
  5. Dim rng As Range
  6. Dim rw As Range, ix As Long
  7. Set rng = Intersect(Selection, ActiveSheet.UsedRange)
  8. If rng Is Nothing Then
  9. MsgBox "nothing in usedrange to be merged"
  10. GoTo done
  11. End If
  12. Dim i As Long, j As Long
  13. For i = 1 To Selection.Areas.Count
  14. For j = 1 To Selection.Areas(i).Columns.Count
  15. Application.DisplayAlerts = False
  16. Selection.Areas(i).Columns(j).MergeCells = True
  17. Application.DisplayAlerts = True
  18. Next
  19. Next
  20. done:
  21. End Sub

URL: http://www.mvps.org/dmcritchie/excel/merge.htm

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.