簡體   English   中英

Excel VBA找不到單元格

[英]Excel VBA No cells were found

我有以下示例代碼可以過濾出數據並粘貼到另一張紙上。

我已經使用過不為空的情況來避免這種情況,但是我仍然出現“無單元格”錯誤,並且我也確信標記為“無單元格”的文件實際上應該具有符合條件的數據。

Set vFind = Range("B2:B" & lastRow).Find(what:="0", LookIn:=xlValues, lookat:=xlWhole)

If Not vFind Is Nothing Then
    filterRange.AutoFilter Field:=2, Criteria1:="=0"
    copyRange1.SpecialCells(xlCellTypeVisible).Copy Destination:=thisws.Cells(RowNo, 3)
    copyRange2.SpecialCells(xlCellTypeVisible).Copy Destination:=thisws.Cells(RowNo, 4)

您擁有的代碼采用當前活動工作表Range("B2:B" & lastRow)
為了確保您獲取正確的數據,請嘗試在Range調用之前添加工作表名稱,如下所示:

Worksheets("SheetName").Activate
Set vFind = Worksheets("SheetName").Range("B2:B" & lastRow).Find(what:="0", LookIn:=xlValues, lookat:=xlWhole)

If Not vFind Is Nothing Then
    filterRange.AutoFilter Field:=2, Criteria1:="=0"
    copyRange1.SpecialCells(xlCellTypeVisible).Copy Destination:=thisws.Cells(RowNo, 3)
    copyRange2.SpecialCells(xlCellTypeVisible).Copy Destination:=thisws.Cells(RowNo, 4)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM