为了循环在excel VBA [英] For loop in excel VBA

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

问题描述

我试图在excel列上使用For循环。这是我的代码:

 为每个c在工作表(sheet1)。范围(A1:A5000)。 
c.Offset(0,1).Range(A1)。Value = Right((Left(c,13)),7)
下一个

它工作正常,问题是与

 范围(A1:A5000)

我的工作表少于1000行,但可以增长我想只能在其中有数据的行上使用循环。
如何更改它从A1到最后一个空行?

解决方案

你可以尝试这个。 ..

  Dim r As Range 

设置r =范围(A65536)。 xlup)

对于每个c在工作表(sheet1)。范围(A1:& r.Address).Cells
c.Offset(0,1).Range A1)Value = Right((左(c,13)),7)
下一个


Im trying to use For loop on an excel column. This is my code:

   For Each c In Worksheets("sheet1").Range("A1:A5000").Cells
        c.Offset(0, 1).Range("A1").Value = Right((Left(c, 13)), 7)
   Next

it works ok the problem is with the

Range("A1:A5000")

my sheet has less then 1000 rows but it can grow and I want to be able to use the loop only on the rows that have data in them. how can I change it to go from A1 to the last not empty row?

解决方案

You may try this ...

Dim r As Range

Set r = Range("A65536").End(xlup)

For Each c In Worksheets("sheet1").Range("A1:" & r.Address).Cells
   c.Offset(0, 1).Range("A1").Value = Right((Left(c, 13)), 7)
Next

这篇关于为了循环在excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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