If you need to refer to the cell as a Range object, then:
Dim Key as Range
Set Key = Sheet1.Range("A" & i)
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)
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…