简体   繁体   English

在vba中选择Excel工作表上的特定范围

[英]select a specific range on a excel sheet in vba

I am trying to developp a small tool in vba and as I am a beginner in this, I am having some trouble. 我正在尝试在vba中开发一个小工具,因为我是初学者,我遇到了一些麻烦。

I would like to apply on specific cells of a column a treatment. 我想在柱子的特定细胞上进行处理。 This is my actual code : 这是我的实际代码:

For Each C In ActiveSheet.UsedRange.Columns("B").Cells

The problem with this code, is that is applying to all the cells of my column B, whereas I would like to stop at a specific line (line which I am getting for another function (GetLine) that I have developped) : 这段代码的问题是,它适用于我的B列的所有单元格,而我想停在一个特定的行(我为另一个我开发的函数(GetLine)得到的行):

Function GetLine(rw As Long) As Long
   GetNextEmptyCell = //my code
End Function

So I would like to know how to specify in my foreach to stop at the number returned by my function. 所以我想知道如何在我的foreach中指定停止我的函数返回的数字。

thanks in advance for your help 在此先感谢您的帮助

你可以使用这样的东西从第1行循环到指定的行:

For Each C In ActiveSheet.Range("B1:B" & GetLine).Cells

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM