我已经用这个代码工作了一个星期了,我对 VBA 还不太熟悉,而且已经快要让它做我需要做的事情了,但是最后一行总是出现“应用程序定义或对象定义错误”。我的代码很简单,它要求在 Sheet1 上输入 3 个数据,将它们放置在正确的位置,然后将每个信息复制到 Sheet2 第一行的相应单元格中,然后搜索第一个输入的值或第一个单元格的值 last4(仍在处理),在 Sheet2 上找到该值的位置的正上方添加一行,然后将第一行复制到新的空行中。现在,如果我能消除该错误并正确搜索我想要的单元格,那么一切都应该顺利运行,任何帮助都值得感激。
Sub CommandButton1_Click()
Dim Last4 As Variant
Dim SerialNum As Variant
Dim ExpDate As Variant
Dim addaul As Worksheet
Do
Last4 = InputBox("Insert the last 4 numbers on the NSN for the Hazmat", "RECEIVED HAZMAT")
Range("D" & Rows.Count).End(xlUp).Offset(1).Value = Last4
Sheets("AUL").Range("A1").Value = Last4
If Last4 = Blank Then Exit Sub
SerialNum = InputBox("Scan the Serial Number of the Hazmat", "RECEIVED HAZMAT")
Range("E" & Rows.Count).End(xlUp).Offset(1).Value = SerialNum
Sheets("AUL").Range("H1").Value = SerialNum
If SerialNum = Blank Then Exit Sub
ExpDate = InputBox("Insert the expiration date for the Hazmat", "RECEIVED HAZMAT")
Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ExpDate
Sheets("AUL").Range("I1").Value = ExpDate
If ExpDate = Blank Then Exit Sub
Sheets("AUL").Select
Sheets("AUL").Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("AUL").Cells.Find(What:="Last4", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Application.CutCopyMode = False
Selection.EntireRow.Insert
Sheets("AUL").Range("A1:O1").Copy
Sheets("AUL").Range("A1:O1" & Rows.Count).End(x1Up).Offset(1, 0).PasteSpecial xlPasteValues <------ ERROR LINE IS THIS ONE
Loop Until Last4 = Blank
End Sub