用VBA写一个单元格H2:I13居中对齐,并添加框线,自动换行的代码
时间: 2023-04-05 11:01:53 浏览: 187
Sub CenterAlign()
Range("H2:I13").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Borders.LineStyle = xlContinuous
End With
End Sub
相关问题
用VBA写一个单元格H2:I13居中对齐,并添加框线的代码
Sub CenterAndBorder()
Range("H2:I13").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
End Sub
vba多单元格合并,单元格内容居中
您可以使用 VBA 中的 Range.Merge 方法来合并多个单元格,使用 Range.HorizontalAlignment 属性将合并后的单元格内容居中。
以下是示例代码:
Sub MergeCells()
Range("A1:B2").Merge
Range("A1:B2").HorizontalAlignment = xlCenter
End Sub
这将合并 A1:B2 区域的单元格,并将其内容居中。
阅读全文