码迷,mamicode.com
首页 > 其他好文 > 详细

合并单元格拆分,并把第一个单元格的值赋给所有被合并单元格

时间:2020-03-20 10:34:43      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:style   row   NPU   range   box   inpu   with   merge   合并   

Sub unmergeRange()
Dim rg As Range
With ActiveSheet
    Set rg = .UsedRange
    rowmax = rg.Rows.Count
    columnmax = rg.Columns.Count
    For i = 2 To rowmax
        For j = 1 To columnmax
            If .Cells(i, j).MergeCells Then
                Call UnMergeFunction(.Cells(i, j).MergeArea)
            End If
        Next
    Next
End With
MsgBox "OK"
End Sub

Sub UnMergeFunction(ra As Range)unmerge the merged range, input the first value into all the merged cells
With ra
    aaa = .Cells(1).Value
    .unmerge
    For Each Ce In .Cells
        Ce.Value = aaa
    Next
End With
End Sub

 

合并单元格拆分,并把第一个单元格的值赋给所有被合并单元格

标签:style   row   NPU   range   box   inpu   with   merge   合并   

原文地址:https://www.cnblogs.com/sundanceS/p/12529974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!