|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
用vba代码需要将E2:E5,F2:F5,G2:G5,H2:H5,I2:I5 单元格分别合并后居中该如何操作。
Range("E2:E5,F2:F5,G2:G5,H2:H5,I2:I5").Select
Range("I2").Activate
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
是可以的
但是因为要用很多次,所以用了变量
Sub 1111()
Dim dks As Long, xhh As Long
dks = Application.WorksheetFunction.CountA(Range("a:a"))
For xhh = 2 To dks Step 4
Range("E" & xhh & ":E" & xhh + 3, "f" & xhh & ":f" & xhh + 3, "g" & xhh & ":g" & xhh + 3, "h" & xhh & ":h" & xhh + 3, "i" & xhh & ":i" & xhh + 3).Select
Range("I" & xhh).Activate
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
提示错误参数号或无效属性赋值,是什么原因呢?
|
|