日记首页
|
列表
|
添加日记
|
管理登陆
标题:vba中单元格位置对齐技巧
<p>Sub 单元格对齐技巧() <br> Dim myRange As Range <br> Set myRange = Range("A1") '指定任意单元格Cells(ii, j) 替换变量 <br> With myRange <br> .Value = "ExcelVBA实用技巧大全" "复制代码时,不要MsgBox<br> .HorizontalAlignment = xlRight <br> MsgBox "水平右对齐。" <br> .HorizontalAlignment = xlLeft <br> MsgBox "水平左对齐。" <br> .HorizontalAlignment = xlCenter <br> MsgBox "水平居中。" <br> .HorizontalAlignment = xlDistributed <br> MsgBox "水平分散对齐。" <br> .VerticalAlignment = xlTop <br> MsgBox "垂直靠上。" <br> .VerticalAlignment = xlBottom <br> MsgBox "垂直靠下。" <br> .VerticalAlignment = xlCenter <br> MsgBox "垂直居中。" <br> .HorizontalAlignment = xlGeneral <br> .VerticalAlignment = xlGeneral <br> MsgBox "恢复默认。" <br> End With <br> Set myRange = Nothing<br> End Sub </p><p></p><hr><p></p><p> With Selection<br> ActiveSheet.UsedRange.HorizontalAlignment = xlRight '对已用区域右对齐<br> End With</p>