我正在使用搜索功能來比較數據,以查看工作表中是否存在標識符,但是如果它的數字不通過VB腳本找到它,如果我手動找到它,它會發現它很好..這是令人難以置信的。Excel VB搜索功能找不到號碼
以下代碼位於循環中,該循環覆蓋一張工作表中的每個SKU ID以查看它是否存在於另一張工作表中。 (如果有更好的方法可以讓我知道) 如果沒有找到sku,它會將它添加到表單中,因爲它通過vb腳本找不到它,即使它已經存在存在...讓我知道如果這沒有意義,我會試着重申。一個SKU總是獨一無二的
Sheets(productsheet).Select
On Error Resume Next
Cells.Find(What:=sku, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If Err.Number <> 0 Then
newSKU = newSKU + 1
Range("A" & CurrentRow).Select
ActiveCell.Value = trimmedSku
ActiveCell.Font.Color = red
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("B" & CurrentRow).Select
ActiveCell.Value = skudescription
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("D" & CurrentRow).Select
ActiveCell.Value = sku
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("I" & CurrentRow).Select
ActiveCell.Value = 1
Range("K" & CurrentRow).Select
ActiveCell.Value = cost
Range("L" & CurrentRow).Select
ActiveCell.Value = price
Range("M" & CurrentRow).Select
ActiveCell.Value = price
Range("O" & CurrentRow).Select
ActiveCell.Value = "Y"
Range("P" & CurrentRow).Select
ActiveCell.Value = "N"
Range("Q" & CurrentRow).Select
ActiveCell.Value = "Y"
Range("AI" & CurrentRow).Select
ActiveCell.Value = 1
CurrentRow = CurrentRow + 1
Else
'Skip because it was found
End If
工作表是否處於活動狀態?還是剛選? – 2011-02-23 15:19:35
。選擇激活它,不是?我也完成了。激活相同的結果。 – Tyler 2011-02-23 15:41:59