您的位置:首页 > 编程语言 > VB

vba操作excel的合并单元格代码

2007-01-25 18:14 435 查看
Sub mergeunit()
Dim spos, epos As Integer
Dim ustr, nowstr As String
spos = 1
epos = 1
ustr = Cells(1, 1)
Application.DisplayAlerts = False

Do
nowstr = Cells(epos, 1)
If nowstr <> ustr Then
Range("A" & spos & ":A" & epos - 1).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
ustr = nowstr
End With
Selection.Merge

spos = epos
End If
epos = epos + 1
Loop While Len(nowstr) > 0
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: