Excel VBA循环公式更改范围 [英] Excel VBA Looping formula to change Range

查看:323
本文介绍了Excel VBA循环公式更改范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个代码来操作L9 : DC9中的数据,但是现在我需要对L10 : DC10L11 : 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆