问题
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?
My current version of Excel is 2013
回答1:
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
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.
回答2:
I suggest using Range("L9").Resize(21,50).Interior.Color = ..
to do it in one statement.
来源:https://stackoverflow.com/questions/31549152/excel-vba-looping-formula-to-change-range