请帮忙。我无法弄清楚如何只使用搜索B和J列。它搜索范围B:B到J:J。其他一切都很好。
Sub Find_Item(SNfound,SNRng,IDFound)
'提示用户在用户表单的文本框中输入序列号或唯一ID号。 '这假设只搜索表2中的B列(序列号)和J(ID号),用户输入的数字 '一切正常,但它不会将搜索限制为仅B列和J列。它正在搜索从B到J的所有列。
Dim FindSNID As String '注意 - SNfound和IDFound是Dim As布尔值,SNRng是Dim As Range
调用ResetFilters'此子目录从活动表中删除所有过滤
FindSNID = SNID_textbox.Value
If Trim(FindSNID) <> "" Then
With Sheets("Inventory").Range("B:B", "J:J")
Set SNRng = .Find(What:=FindSNID, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not SNRng Is Nothing Then
SNRng.Activate
&#39;如果在B列(序列号)中找到匹配项,则显示找到该项目的MsgBox,并且它的自身位置是来自W列的xxxxxx(偏移0,21)_ &#39;并且它的当前状态可用或已签出(偏移0,23)
If SNRng.Column = 2 Then
MsgBox "A matching serial number was found in location " & SNRng.Offset(0, 21).Value & vbCrLf & _
"It's current status is " & SNRng.Offset(0, 23).Value
Areabox2.Value = SNRng.Offset(0, 28).Value
Sectionbox2.Value = SNRng.Offset(0, 29).Value
Shelfbox2.Value = SNRng.Offset(0, 30).Value
SNfound = True
IDFound = False
End If
&#39;如果在J列(ID号)中找到匹配项,则会显示该项目的货架位置和状态。
If SNRng.Column = 10 Then
MsgBox "A matching ID number was found in location " & SNRng.Offset(0, 13).Value & vbCrLf & _
"It's current status is " & SNRng.Offset(0, 15).Value
Areabox2.Value = SNRng.Offset(0, 28).Value
Sectionbox2.Value = SNRng.Offset(0, 29).Value
Shelfbox2.Value = SNRng.Offset(0, 30).Value
SNfound = False
IDFound = True
End If
End If
End With
End If
End Sub
答案 0 :(得分:0)
尝试通过设置范围变量=联合(范围(&#34; B:B&#34;),范围(&#34; J:J&#34;))来创建范围
答案 1 :(得分:0)
我终于想出了如何让Union方法起作用。 我改变了这个:
设置SNRng = .Find(What:= FindSNID,_
对此:
设置SNRng = Union(范围(“B:B”),范围(“J:J”))。查找(What:= FindSNID,_
现在搜索只搜索B和J列。