Office中国论坛/Access中国论坛
标题:
怎么用VBA进行格式设置呢
[打印本页]
作者:
zhuangyongjin
时间:
2015-12-17 16:01
标题:
怎么用VBA进行格式设置呢
怎么用VBA进行格式设置呢
作者:
roych
时间:
2015-12-17 17:32
本帖最后由 roych 于 2015-12-18 14:40 编辑
Sub test()
Dim i As Long
Dim j As Long
For i = 1 To 17
j = i Mod 4
With Sheets(1).Range("A2:H2").Offset(i, 0)
Select Case j
Case Is = 1
.Font.Color = vbRed
Case Is = 2
.Font.Bold = True
.Font.Name = "隶书"
Case Is = 3
.Font.Italic = True
Case Is = 0
.Interior.Color = vbYellow
End Select
End With
Next
End Sub
复制代码
代码已修正。[attach]57569[/attach]
作者:
zhuangyongjin
时间:
2015-12-21 10:26
roych 发表于 2015-12-17 17:32
代码已修正。
你好,谢谢您帮忙。已解决了我的问题。
不过,我将行号改为动态的后,需要加一个IF条件,否则空白的单元格也会出现黄色的底纹
Sub test()
Dim rng As Range
'rng.Cells.Interior.Color
Dim i As Long, r As Integer
Dim j As Long
r = [a65536].End(xlUp).Row
Cells.ClearFormats
For i = 1 To r
j = i Mod 4
With Sheets(1).Range("A2:H2").Offset(i, 0)
If Cells(i + 2, 1) <> "" Then
Select Case j
Case Is = 1
.Font.Color = vbRed
Case Is = 2
.Font.Bold = True
.Font.Name = "隶书"
Case Is = 3
.Font.Italic = True
Case Is = 0
.Interior.Color = vbYellow
End Select
End If
End With
Next
End Sub
复制代码
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3