查找特定的单元格Excel VBA宏 [英] Find specific cell Excel VBA macro

查看:298
本文介绍了查找特定的单元格Excel VBA宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在for循环中定义一个变量,作为一个特定的单元格,将随着for循环遍历而改变。我只是不确定这样做的语法。这是我到目前为止。我该怎么做才刚刚解释的呢?任何帮助将不胜感激。

I want to define a variable in a for loop as a specific cell that will change as the for loop iterates through. I am just unsure of the syntax to do so. This is what I have so far. How could I make this do what I just explained? Any help would be greatly appreciated.

Key = Sheet1.Columns("A:A").Rows("i")


推荐答案

如果您需要参考单元格作为Range对象,然后:

If you need to refer to the cell as a Range object, then:

Dim Key as Range
Set Key = Sheet1.Range("A" & i)

您必须使用 Set 关键字分配给对象变量时。一个范围是一个对象。

You must use the Set keyword when assigning to an object variable. A Range is an object.

如果您只需要参考单元格的,然后:

If you need to refer only to the cell's value, then:

Dim Key as Variant
Key = Sheet1.Range("A" & i)

我声明作为类型变式,因为单元格可能包含错误值/ etc。如果您将变量严格定义为 String Long 等。

I declare Key as type Variant because cells may contain error values/etc. which will cause an error if you strictly define the variable as type like String or Long, etc.

这篇关于查找特定的单元格Excel VBA宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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