Вы находитесь на странице: 1из 1

Sub MergeRxR_Join()

'-- Merge cells in multiple selected areas Row by Row ---


' limited to the usedrange (Ctrl+End)
' JOIN contents of cells before merging
' D.McRitchie, 2002-05-31 in merge.htm
Dim Str As String, ii As Long
Str = "!"
Dim rng As Range
Dim rw As Range, ix As Long
Set rng = Intersect(Selection, ActiveSheet.UsedRange)
If rng Is Nothing Then
MsgBox "nothing in usedrange to be merged"
GoTo done
End If
Dim i As Long, j As Long
For i = 1 To Selection.Areas.Count
For j = 1 To Selection.Areas(i).Rows.Count
Application.DisplayAlerts = False
Str = "!" '... concatenate cells for this row in selection
For ii = 1 To Selection.Areas(i).Rows(j).Columns.Count
Str = Str & "!" & Selection.Areas(i).Rows(j).Columns(ii)
Next ii
Str = Mid(Str, 2)
Selection.Areas(i).Rows(j)(1) = Str
Selection.Areas(i).Rows(j).MergeCells = True
Application.DisplayAlerts = True
Next
Next
done:
End Sub

Вам также может понравиться