简体   繁体   English

如何在vba中存储范围的行和列号,为什么会出现438运行时错误?

[英]How can I store the row and column numbers of a range in vba, and why am I getting a 438 runtime error?

I'm trying to capture the row and column numbers of a ranger in variables. 我正在尝试捕获变量中游侠的行号和列号。

After a fair amount of googling, it seems I might have to store these as Longs and not Integers, but not sure. 经过大量的谷歌搜索之后,似乎我可能不得不将它们存储为Longs而不是Integers,但是不确定。 Either way I get the same "438 object doesn't support this property or method" error when I reach the line "r1 = wb.ws1.Range("CI14").Row" as below. 无论哪种方式,当我到达如下所示的行“ r1 = wb.ws1.Range(“ CI14”)。Row“时,都会收到相同的“ 438对象不支持此属性或方法”错误。

Dim wb As Workbook
Set wb = Application.Workbooks("test.xlsm")
Dim ws1 As Worksheet
Set ws1 = wb.Worksheets("Worksheet1")

Dim r1 As Long
r1 = wb.ws1.Range("CI14").Row
Dim c1 As Long
c1 = wb.ws1.Range("CI14").Column
Dim rng1 As Range
Set rng1 = wb.ws1.Cells(r1, c1)

I am trying to get something I can iterate on in a while loop, like so: 我正在尝试获取可以在while循环中迭代的内容,例如:

Do Until IsEmpty(rng1.Value)
    (conditional statement)
    r1 = r1 + 1
    Set rng1 = wb.ws1.Cells(r1, c1)
Loop

ws1 is an object, it is not a Method or Property of your wb object. ws1是一个对象,不是wb对象的“方法”或“属性”。

The correct syntax is: 正确的语法是:

r1 = ws1.Range("CI14").Row

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

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