簡體   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