设置单元格垂直和水平对齐的VBA语句:
Selection.HorizontalAlignment = xlLeft
Selection.VerticalAlignment = xlCenter
右对齐参数是xlRight
Sub cell()
Dim icell As Integer, hcell As Integer
For icell = 4 To 35
If UCase(Cells(icell, 1).Value) = "SAT" Or UCase(Cells(icell, 1).Value) = "SUN" Then
Cells(icell, 1).Value = UCase(Cells(icell, 1).Value)
For hcell = 1 To 21
Cells(icell, hcell).Interior.Color = RGB(200, 200, 200)
Cells(icell, 1).HorizontalAlignment = xlCenter
Cells(icell, 1).VerticalAlignment = xlCenter
Cells(icell, 1).Font.Bold = True
Next
End If
Next
End Sub
Range("a1").HorizontalAlignment = xlCenter '水平居中
Range("a1").VerticalAlignment = xlCenter '垂直居中
属性参数值
xlBottom
xlCenter
xlDistributed
xlJustify
xlTop