我收到运行时错误'13':在下面标记的其中一行输入不匹配。我希望能够有一个用户窗体,您可以在其中键入两个条件,然后它将搜索同时具有这两个条件的行,并将相应单元格的值粘贴到11个用户窗体文本框中。我不确定为什么它会给我这行错误,或者是否有更好的方法可以做到这一点。
Private Sub CommandButton1_Click()
txt1.Visible = True
txt2.Visible = True
txt3.Visible = True
txt4.Visible = True
txt5.Visible = True
txt6.Visible = True
txt7.Visible = True
txt8.Visible = True
txt9.Visible = True
txt10.Visible = True
txt11.Visible = True
Dim ws As Worksheet
Set ws = Sheets("The Goods")
ws.activate
Dim SearchSearch As Variant
SearchSearch = txtsearch.Value
Dim SearchName As Variant
SearchName = txtname.Value
If Trim(txtsearch.Value) = "" Then
MsgBox "Search can't be left blank.",vbOKOnly + vbInformation,"Search"
End If
If Trim(txtname.Value) = "" Then
MsgBox "Name can't be left blank.","Name"
End If
Dim FirstAddress As String,cF As Range
With ThisWorkbook.Sheets("The Goods").Range("D:D") 'txtsearch will be in the range D:D
Set cF = .Find(What:=SearchSearch,_
after:=activeCell,_
LookIn:=xlValues,_
LookAt:=xlPart,_
SearchOrder:=xlByColumns,_
SearchDirection:=xlNext,_
MatchCase:=False,_
SearchFormat:=False) ' line that is giving me an error
With ThisWorkbook.Sheets("The Goods").Range("B:B") 'txtname will be in the range B:B
Set cF = .Find(What:=SearchName,_
SearchFormat:=False)
txt1.Value = cF.(0,5).Value
txt2.Value = cF(0,3).Value
txt3.Value = cF(0,6).Value
txt4.Value = cF(0,7).Value
txt5.Value = cF(0,8).Value
txt6.Value = cF(0,9).Value
txt7.Value = cF(0,10).Value
txt8.Value = cF(0,11).Value
txt9.Value = cF(0,12).Value
txt10.Value = cF(0,13).Value
txt11.Value = cF(0,14).Value
End With
End With
End Sub
Private Sub CommandButton3_Click()
Dim iExit As VbMsgBoxResult
iExit = MsgBox("Are you sure you want to exit?",vbQuestion + vbYesno,"Search System")
If iExit = vbYes Then
Unload Me
End If
End Sub