View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
XLuser XLuser is offline
external usenet poster
 
Posts: 1
Default Macro for merging cells


Problem solved

I found an example published by Frank Kabel in Maj 2004 and with the
help of others here at the company we modified it some and came up with
this:


Code:
--------------------
Sub mergebycol()
Dim lastrow As Long
Dim row_index As Long
Dim col_index As Long
Dim start_index As Long
Dim wks As Worksheet
Set wks = ActiveSheet
With wks
For col_index = 1 To 3
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
start_index = 1
For row_index = 2 To lastrow + 1
If .Cells(row_index, col_index).Value < .Cells(row_index - 1, col_index).Value Then
If row_index - start_index 1 Then
Application.DisplayAlerts = False
With Range(.Cells(start_index, col_index), .Cells(row_index - 1, col_index))
.Merge
.VerticalAlignment = xlCenter
End With
Application.DisplayAlerts = True
End If
start_index = row_index
End If
Next
Next
End With
End Sub
--------------------


--
XLuser
------------------------------------------------------------------------
XLuser's Profile: http://www.excelforum.com/member.php...o&userid=32347
View this thread: http://www.excelforum.com/showthread...hreadid=521094