Excel VBA循环公式更改范围 [英] Excel VBA Looping formula to change Range
问题描述
我已经编写了一个代码来操作L9 : DC9
中的数据,但是现在我需要对L10 : DC10
,L11 : DC11
等重复此操作.我尝试了For Next
循环来替换L9 : DC9
中的值. Li:DCi
的范围,并指定(i
)为9到30,但出现错误.如何为此功能循环?
I've written a code to manipulate data in L9 : DC9
, But now I need to repeat this for L10 : DC10
, L11 : DC11
and etc.. I've tried a For Next
loop replacing the value in the range with Li:DCi
and specifying (i
) as 9 to 30 but I get an error. How can I make a loop for this function?
我当前的Excel版本是2013
My current version of Excel is 2013
推荐答案
您正在寻找的是这样的语法
What you are looking for is a syntax like this
Sub LoopRows()
Dim i As Integer
For i = 9 To 30
ActiveSheet.Range("L" & i & ":DC" & i).Interior.Color = RGB(100, 100, 100)
Next i
End Sub
此示例仅格式化每一行中单元格的颜色.请注意,我是如何使用for循环创建循环范围选择的.
This example just formats the color of the cell in each row. Notice how I use the for-loop to create a looping range selection.
这篇关于Excel VBA循环公式更改范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!