我正在使用搜索功能来比较数据,以查看工作表中是否存在标识符,但是如果它的数字不通过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