开发者

How to use a counter as an argument in functions?

开发者 https://www.devze.com 2023-01-23 22:31 出处:网络
a standard loop in Excel VBA goes l开发者_StackOverflow中文版ike this: dim i as integer for i = 1 to 100

a standard loop in Excel VBA goes l开发者_StackOverflow中文版ike this:

dim i as integer
for i = 1 to 100 
<do program>
next
end sub

Now, my question is: how can I use the counter, i, as an argument in the program?

example:

dim i as integer
for i = 1 to 100 

If Range("Ci") = 0 Then
Rows("i:i").Select
Rows.Delete

next
end sub


You should be able to do something like this:

 dim i as integer
 for i = 1 to 100 

      If Range("C" & i) = 0 Then
           Rows(i & ":" & i).Select
           Rows.Delete
      end if
 next
 end sub

The & is the concatenation operator which is used to add a string onto another string.

Now i is obviously a number in the above example, but VBScript is smart enough to know what you're doing and, for example, just stick "C" and the current value of i together.

0

精彩评论

暂无评论...
验证码 换一张
取 消