码迷,mamicode.com
首页 > 编程语言 > 详细

合并单元格/VBA

时间:2015-08-11 17:58:37      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

 合并某一列中相同数据的单元格
Sub MergeColumns()
    Dim rowN As Integer
    Dim i, j, m, n As Integer
    
    Dim col As Integer
    col = 2              合并哪一列的单元格
    
    Application.DisplayAlerts = False
    rowN = Cells(65535, col).End(3).Row
    For i = 2 To rowN
        For j = i + 1 To rowN
            If Cells(j, col).Value <> Cells(i, col).Value Then
                m = i
                n = j - 1
                Range(Cells(m, col), Cells(n, col)).Merge
                i = n
                Exit For
            End If
        Next j
    Next i
    MsgBox "完成!"
End Sub

 

合并单元格/VBA

标签:

原文地址:http://www.cnblogs.com/z5337/p/4721433.html

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