读书人

合并单元格的有关问题

发布时间: 2012-01-19 20:57:58 作者: rapoo

合并单元格的问题

在VBA中想要合并相邻的两个单元格,如果两个单元格中都有数据那么Excel会弹出对话框,问你是否确定保留左边单元格数据,但是我不想要弹出这个对话框,怎么实现呀,谢谢大家
下面是例子,合并B2和C2单元格,如果B2和C2中都有数据,那么就会弹出提示框。

Worksheets("sheet1").Range(B2:C2).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge

[解决办法]

VB code
Sub Macro1()'' Macro1 Macro' 宏由 HG 录制,时间: 2010-2-19' Application.DisplayAlerts = False    Range("A1:A2").Select    With Selection        .HorizontalAlignment = xlCenter        .VerticalAlignment = xlCenter        .WrapText = False        .Orientation = 0        .AddIndent = False        .IndentLevel = 0        .ShrinkToFit = False        .ReadingOrder = xlContext        .MergeCells = False    End With    Selection.Merge   End Sub 

读书人网 >VB

热点推荐