2

I want to loop through every row and do some actions for multiple cells selected, e.g. K3,N3,Q3,T3,W3,Z3 next K4,N4,Q4... etc.

What am I doing wrong?

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 
1
  • What's the problem? Please quote the error message. Commented Mar 22, 2013 at 23:27

2 Answers 2

4

There is no need to loop. You can use the below code.

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 
Sign up to request clarification or add additional context in comments.

1 Comment

This is a much better solution. No need for a loop.
3

You need to pass in the range as 1 argument. Try this:

Range("K" & counter & ",N" & counter & ",Q" & counter & ",T" & counter & ",W" & counter & ",Z" & counter).Select 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.