我想循环遍历每一行并对所选的多个单元格执行某些操作,例如K3,N3,Q3,T3,W3,Z3
下一个K4,N4,Q4...
等。
我做错了什么?
Sub Colors_test()
For counter = 3 To 110
Range("K" & counter, "N" & counter, "Q" & counter, "T" & _
counter, "W" & counter, "Z" & counter).Select
Selection.FormatConditions.AddColorScale ColorScaleType:=3
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).ColorScaleCriteria(1).Type = _
xlConditionValueLowestValue
With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
.Color = 7039480
.TintAndShade = 0
End With
Selection.FormatConditions(1).ColorScaleCriteria(2).Type = _
xlConditionValuePercentile
Selection.FormatConditions(1).ColorScaleCriteria(2).Value = 50
With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
.Color = 8711167
.TintAndShade = 0
End With
Selection.FormatConditions(1).ColorScaleCriteria(3).Type = _
xlConditionValueHighestValue
With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
.Color = 8109667
.TintAndShade = 0
End With
Next counter
MsgBox "Ok All " & counter
End Sub
答案 0 :(得分:3)
无需循环。您可以使用以下代码。
Sub Colors_test()
With Range("K3:K110,N3:N110,Q3:Q110,T3:T110,W3:W110,Z3:Z110")
.Select
// your code here
End With
End Sub
答案 1 :(得分:2)
您需要将范围作为1参数传递。试试这个:
Range("K" & counter & ",N" & counter & ",Q" & counter & ",T" & counter & ",W" & counter & ",Z" & counter).Select