我想在所选行的输入框中找到我输入的日期。我正在接受
运行时错误91对象变量或使用块变量不设置
f.Select
行的错误。请告诉我做错了什么。非常感谢。
Sub Add_Batch_Macro()
Dim mRange As Range
Dim New_Batch_Date As Date
Dim f As Variant
Range("A1").Select
ActiveCell.Rows("1:5").EntireRow.Select
Selection.Copy
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
ActiveSheet.Paste
wsDate_Header_Row = ActiveCell.Row
var_Batch_Qty = InputBox("Batch Quantity is:", "Enter the Batch Quantity:", "")
ActiveCell.Offset(4, 3).Select
Selection.Value = var_Batch_Qty
ActiveCell.Offset(-2, 1).Select
ActiveCell.FormulaR1C1 = "=R[2]C4-R[-1]C"
Application.CutCopyMode = False
New_Batch_Date = InputBox("Use Format: mmddyyyy", "Enter the New Batch Date:", "")
Application.Rows(wsDate_Header_Row).Select
Set mRange = ActiveSheet.Range(ActiveSheet.Cells(wsDate_Header_Row, 1), ActiveSheet.Cells(wsDate_Header_Row, 20))
Set f = mRange.Find(What:=New_Batch_Date, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
f.Select
End Sub
答案 0 :(得分:1)
根据其他答案的OP评论编辑。
Dim mRange As Range
Dim New_Batch_Date As Date
Dim f As Variant
wsDate_Header_Row = ActiveCell.Row
New_Batch_Date = InputBox("Use Format: mm-dd-yyyy", "Enter the New Batch Date:", "")
Set mRange = Range(Cells(wsDate_Header_Row, 1), Cells(wsDate_Header_Row, 20))
Set f = mRange.Find(What:=New_Batch_Date, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
f.Select
答案 1 :(得分:0)
尝试创建范围对象变量时,必须将其设置为范围对象。当您使用Set mRange = wsDate_Header_Row
时,您试图将其设置为行号而不是对象。您应该使用Set mRange = Cells(wsDate_Header_Row, column_number_or_letter)
之类的内容,其中column_number_or_letter指向您的目标列。