我在Range中有几个单元格(“I1:I100”)。我需要为整行着色。我已经记录了VBA,但它显示了一些错误。
ActiveSheet.Range("I1:I100").AutoFilter Field:=1, Criteria1:=RGB(255, 255 _
, 0), Operator:=xlFilterCellColor
Rows.Activate.Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveSheet.Range("$A$1:$G$9").AutoFilter Field:=1
但可以通过声明变量来获得SIMPLE代码。
答案 0 :(得分:1)
Rows.Activate.Select
是您发生错误的地方,因为您无法.Activate.Select
。请仔细阅读How to avoid using .Select
/.Activate
,然后尝试以下内容:
Sub t()
' What's this next line supposed to do?
'ActiveSheet.Range("I1:I100").AutoFilter Field:=1, Criteria1:=RGB(255, 255 _
, 0), Operator:=xlFilterCellColor
With Rows("1:100").Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveSheet.Range("$A$1:$G$9").AutoFilter Field:=1
End Sub