首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

合并单元格的有关问题

2012-01-19 
合并单元格的问题在VBA中想要合并相邻的两个单元格,如果两个单元格中都有数据那么Excel会弹出对话框,问你

合并单元格的问题
 
在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 

热点排行