繁体   English   中英

如何使用 .Find 设置 Range 变量?

[英]How to set a Range variable using .Find?

我正在尝试使用.Find函数将范围变量“rcell”设置为等于包含变量“lot”值的单元格的范围。

我想在特定范围(D 列)而不是所有单元格中进行搜索。

我收到类型不匹配错误。

我尝试使用“列(4)”而不是“范围(D:D)”。

Workbooks("lotworkbook.xlsx").Activate
Sheets("Sheet1").Select
lot = Cells(row, 3)
Workbooks("findworkbook.xlsx").Activate
Sheets(3).Select
            
Dim rcell As Range
Set rcell = Range("D:D").Find(What:=lot, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) 'this is the line with issues'
            
If rcell Is Nothing Then

Else

' ...

预期结果:在某个工作表中找到具有变量“lot”值的单元格,并在另一个工作表上找到该值,并将范围变量“rcell”设置为等于该单元格位置。

实际结果:类型不匹配错误。 这适用于Cells.Find但不适用于Range("D:D").Find

相信问题是After:=ActiveCell - 删除它After:=ActiveCell试:

Dim rcell As Range
Set rcell = Range("D:D").Find(What:=lot, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) 'this is the line with issues

暂无
暂无

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

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