2013-03-22 1 views
2

모든 행을 반복하고 선택한 여러 셀에 대해 몇 가지 작업을 수행하려고합니다. 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

무엇이 문제입니까? 오류 메시지를 인용하십시오. – Sebastian

답변

2

1 개의 인수로 범위를 전달해야합니다. 이것을 시도하십시오 :

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

작동 중입니다 !!! – blademyc

2

반복 할 필요가 없습니다. 아래 코드를 사용할 수 있습니다.

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

이것은 훨씬 더 나은 해결책입니다. 루프가 필요 없습니다. –

+0

@DavidZemens 감사 –