vba 多个单元格选择,而不是范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15581368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 15:15:00 来源:igfitidea点击:
Multiple cells selection, not range
提问by blademyc
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.
我想遍历每一行并对选定的多个单元格执行一些操作,例如K3,N3,Q3,T3,W3,Z3
下一个K4,N4,Q4...
等。
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
采纳答案by PeteGO
You need to pass in the range as 1 argument. Try this:
您需要将范围作为 1 个参数传递。尝试这个:
Range("K" & counter & ",N" & counter & ",Q" & counter & ",T" & counter & ",W" & counter & ",Z" & counter).Select
回答by
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