我有一个搜索工作簿的脚本,然后在工作表上打印结果。这一切似乎都运行得很好,但我遇到的一个问题是,每当我打开文件时,我都会得到运行时错误424。 调试器在Sub UpdateSearchBox()下停止,它是第4行或"如果是TextBox1.Value<> ""然后"
这是代码。
Private Sub ComboBox1_Change()
End Sub
Private Sub ComboBox2_Change()
UpdateSearchBox
End Sub
Private Sub CommandButton1_Click()
Select Case TextBox1.Value
Case "F"
TextBox1.Value = "G"
Case "E"
TextBox1.Value = "F"
Case "D"
TextBox1.Value = "E"
Case "C"
TextBox1.Value = "D"
Case "B"
TextBox1.Value = "C"
Case "A"
TextBox1.Value = "B"
Case "G"
TextBox1.Value = "A"
End Select
End Sub
Private Sub CommandButton2_Click()
FindOne
End Sub
Private Sub TextBox1_Change()
UpdateSearchBox
End Sub
Sub UpdateSearchBox()
Dim PageName As String, searchColumn As String, ListFiller As String
Dim lastRow As Long
If TextBox1.Value <> "" Then
PageName = TextBox1.Value
Else
Exit Sub
End If
Select Case ComboBox2.Value
Case "EQUIPMENT NUMBER"
searchColumn = "A"
Case "EQUIPMENT NAME"
searchColumn = "C"
Case "DUPONT NUMBER"
searchColumn = "F"
Case "SAP NUMBER"
searchColumn = "G"
Case "SSI NUMBER"
searchColumn = "H"
Case "PART NAME"
searchColumn = "I"
Case ""
MsgBox "Please select a value for what you are searching by."
End Select
lastRow = Sheets(PageName).Range("A65536").End(xlUp).Row
If lastRow <> 0 And PageName <> "" And searchColumn <> "" Then
ListFiller = PageName & "!" & searchColumn & "2" & ":" & searchColumn & lastRow
ComboBox1.ListFillRange = ListFiller
End If
End Sub
Sub FindOne()
Range("B19:J1500") = ""
Application.ScreenUpdating = False
Dim k As Integer, EndPasteLoopa As Integer
Dim myText As String, searchColumn As String
Dim totalValues As Long
Dim nextCell As Range
k = ThisWorkbook.Worksheets.Count
myText = ComboBox1.Value
Set nextCell = Range("B20")
If myText = "" Then
MsgBox "No Address Found"
Exit Sub
End If
Select Case ComboBox2.Value
Case "EQUIPMENT NUMBER"
searchColumn = "A"
Case "EQUIPMENT NAME"
searchColumn = "C"
Case "DUPONT NUMBER"
searchColumn = "F"
Case "SAP NUMBER"
searchColumn = "G"
Case "SSI NUMBER"
searchColumn = "H"
Case "PART NAME"
searchColumn = "I"
Case ""
MsgBox "Please select a value for what you are searching by."
End Select
For i = 2 To k
totalValues = Sheets(i).Range("A65536").End(xlUp).Row
ReDim AddressArray(totalValues) As String
For j = 0 To totalValues
AddressArray(j) = Sheets(i).Range(searchColumn & j + 1).Value
Next j
For j = 0 To totalValues
If (myText = AddressArray(j)) Then
EndPasteLoop = 1
If (Sheets(i).Range(searchColumn & j + 2).Value = "") Then EndPasteLoop = Sheets(i).Range(searchColumn & j + 1).End(xlDown).Row - j - 1
For r = 1 To EndPasteLoop
Range(nextCell, nextCell.Offset(0, 8)).Value = Sheets(i).Range("A" & j + r, "I" & j + r).Value
Set nextCell = nextCell.Offset(1, 0)
Next r
End If
Next j
Next i
Application.ScreenUpdating = True
End Sub