Excel Merge Cells

3002 단어 Excel
Sub  Macro1()
   Application .ScreenUpdating = False
    Application .DisplayAlerts = False   '  
    Dim  rng As  Range
    Set  rng = Cells(1 , 1 )  ' A1 
    For  i = 1  To  Range("a65536" ).End (xlUp).Row + 1
        If  Trim (Cells(i, 1 ))  = ""  Then  ' 
            Set  rng = Union(rng, Cells(i, 1 ))
        Else
            rng.Merge: Set  rng = Cells(i, 1 )
        End  If
    Next  i
    Application .ScreenUpdating = True
    Application .DisplayAlerts = True
End  Sub
 
1. Determine whether the cell is included in the merged cell. The MergeCells property can be used to determine whether a cell is included in a merged cell. For example, if A1:B2 is merged into a merged cell, then: Range("A1").MergeCells will return True!
2. Get the merged area containing the specified cells. The MergeArea property can obtain the merged area containing the specified cells, such as: A1:B2 is merged into a merged cell, then: Range("A1").MergeArea.Address will return $A$1:$B$2.
3. Merge replication. When merging cells, we often encounter that in the merged cell range, there are multiple cells with content, and when merging cells, it will prompt that only the data in the upper left corner can be retained. After the content is merged, all the content is also merged into the merged cell, you can use this custom macro to complete
 
 
 




Sub  2()
    Dim c As Range, r As Range, i As Integer, x, n As New Collection, Str As String
    With Sheet2
        .Range(.[A2], .[C2].End(xlDown)).ClearContents
        Set c = [A2]
        Set r = .[A2]
    End With
    Do While c <> ""
        x = Split(c.Offset(0, 2), "/")  ' C 
        For i = 0 To UBound(x)
            If x(i) <> "" Then
                On Error Resume Next
                n.Add x(i), CStr(x(i))
                On Error GoTo 0
            End If
        Next
        If c <> c.Offset(1, 0) Then  ' 
            For i = 1 To n.Count
            Str = Str & IIf(Str = "", "", "、") & n.Item(1) ' , 
                n.Remove (1)
            Next
                r = c '  
                r.Offset(0, 1) = c.Offset(0, 1)
                r.Offset(0, 2) = Str
                Str = ""
                Set r = r.Offset(1, 0) ' 
        End If
        Set c = c.Offset(1, 0) ' 
    Loop
End Sub

 


Fill blank cells






Range("P7:P13").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "=R[-1]C"

좋은 웹페이지 즐겨찾기