----------------------------------------------------------------
1 2 3 | Sub Sample1() Range("A1:B5").Merge End Sub |
----------------------------------------------------------------
Now, how to check cells merge or not,
1 2 3 4 5 6 7 8 9 10 11 | Sub Sample2() Dim i As Long, buf As String For i = 9 To 22 If Cells(i, 1).MergeCells Then buf = buf & Cells(i, 1).Address(0, 0) & "-->Merged Cell" & vbCrLf Else buf = buf & Cells(i, 1).Address(0, 0) & "-->Not Merge Cell" & vbCrLf End If Next i MsgBox buf End Sub |
----------------------------------------------------------------
Merge Area
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Sub Sample3() Dim Target As String, i As Long, buf As String, c Target = InputBox("Seelct Year Target") If Target = "" Then Exit Sub For i = 9 To 22 If Cells(i, 1) = Target Then buf = Target & "(" & Cells(i, 1).Address(0, 0) & ")" & vbCrLf buf = buf & "----------" & vbCrLf For Each c In Cells(i, 1).MergeArea buf = buf & c.Address(0, 0) & vbCrLf Next c MsgBox buf Exit For End If Next i End Sub |
----------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 | Sub Sample4() Dim buf As String With Range("A30").MergeArea buf = buf & .Rows.Count & " row" & vbCrLf buf = buf & .Columns.Count & " coloum" & vbCrLf buf = buf & .Count & " cells" & vbCrLf buf = buf & .Item(1).Address(0, 0) & " :top left " & vbCrLf buf = buf & .Item(.Count).Address(0, 0) & " :bottom right" End With MsgBox buf End Sub |
----------------------------------------------------------------
Link file download
No comments :
Post a Comment