乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>excel</em> <em>vba</em> 自动合并单元格-

<em>excel</em> <em>vba</em> 自动合并单元格-

作者:乔山办公网日期:

返回目录:excel表格制作


  1. MergeArea属性:返回一个 Range对象,该对象代表包含指定单元格的合并区

  2. 通过MergeArea.rows.count获得合并区域的行数,MergeArea.columns.count获得合并区域的列数

   故题目中要统计cells(i,j)所在的合并单元格的合并个数就可以用下面代码实现:

sub main

ro=cells(i,j).MergeArea.Rows.Count

co=cells(i,j).MergeArea.Columns.Count

su=ro*co

msgbox "指定单元格合并区域包含”& su &"个单元格”

end sub



(将合并单元格中的数据也合并)

比如这是你要合并两个单元格里的数据,做法如下

A       B      C  

255    8146 

在C1单元格里输入=A1&""&B1

注意,在两个双引号里不能有空格,否则就会变成e79fa5e98193e58685e5aeb9339 255 8146

(多元合并,且保留多元数据)

Sub 合并同类项()

If Selection.Columns.Count > 1 Then MsgBox "只能对单列操作,请重新选择区域!": Exit Sub

Selection.Offset(0, 1).EntireColumn.Insert

With Selection

For i = .Cells.Count To 2 Step -1

If .Cells(i) = .Cells(i - 1) Then Range(.Cells(i).Offset(0, 1), .Cells(i - 1).Offset(0, 1)).Merge

Next

Selection.Offset(0, 1).Copy

.PasteSpecial xlPasteFormats

.Offset(0, 1).EntireColumn.Delete

End With

End Sub

3、


Public Sub 顺序合并内容同单()
    Dim CXrng As Range, Rng As Range, i As Long
    Set Rng = Sheets("sheet2").Range("A1")
    For Each CXrng In Sheets("Sheet1").Range("A1:A" & Sheets("Sheet1").Range("A65536").End(xlUp).Row)
        If CXrng.Value <> Rng.Value Then
            If i <> 0 Then Rng.Resize(i, 1).Merge
            Set Rng = Sheets("sheet2").Range("A" & CXrng.Row)
            Rng.Value = CXrng.Value
            i = 1
        Else
            i = i + 1
        End If
    Next
    If i <> 0 Then Rng.Resize(i, 1).Merge
End Sub


Sub s()
    For i = 2 To 12
        a = Cells(5, i).Text
        n = Len(a)
        For j = 1 To n
            b = Mid(a, j, 1)
            If IsNumeric(b) Then c = c & b
        Next
    Next
    With Sheet2
        i = 11
        Do While .Cells(i, 4) <> ""
            If i = 19 Then MsgBox "无位zd": End
            i = i + 1
        Loop
        .Cells(i, 4).NumberFormatLocal = "@"
        .Cells(i, 4) = c
    End With
End Sub

相关阅读

  • <em>excel</em> <em>vba</em> 自动合并单元格-

  • 乔山办公网excel表格制作
  • MergeArea属性:返回一个 Range对象百,该对象代表包含指定单元格度的合并区知域通过MergeArea.rows.count获得合并区域的行数,MergeArea.columns.count获得合并区域的列数 故题目中要统道计cel
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网