2016-04-04 11 views
0

現在、強調表示されたコードに実行時エラー'91 'オブジェクト変数またはブロック変数が設定されていません。このコードの目的は、ユーザーフォームからの入力に基づいて名前付き製品を検索し、利用可能な数量にオフセットすることです。その後、現在の値を注文数量で引いて古い値を新しい値に置き換えます。ユーザーフォームの入力に基づいて古い値を新しい値に置き換えます。

Private Sub btnAdd_Order_Click() 
Dim X As Integer 
Dim nextrow As Range 
Dim DateCus As Range 
Dim i As Range 

If Me.txtOrder_No.Value = "" Then 
MsgBox "Add an Order No" 
Exit Sub 
End If 

If Me.Order1.Value = "" And Me.Qty1.Value = "" Then 
MsgBox "No order was specified. Please input an order" 
Exit Sub 
Else 
For X = 1 To 8 

Set nextrow = Sheet6.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) 
If Me.Controls("Order" & X).Value > "" And Me.Controls("Qty" & X).Value > "" Then 

If Me.Controls("Qty" & X).Value < Application.WorksheetFunction.VLookup(Me.Controls("Order" & X), Sheet4.Range("Products"), 4, 0) Or Me.Controls("Qty" & X).Value = Application.WorksheetFunction.VLookup(Me.Controls("Order" & X), Sheet4.Range("Products"), 4, 0) Then 

'This is the one causing the error 
Set i = Sheet3.Range("Ingredients").Find(Me.Controls("Order" & X).Value).Offset(0, 3) 

i = Application.WorksheetFunction.VLookup(Me.Controls("Order" & X), Sheet4.Range("Products"), 4, 0).Value - Me.Controls("Qty" & X).Value 



'End If 

Else 
MsgBox "There's no stock available for one of the orders" 
+0

エラーの原因となっている行をメモするのに役立ちます。 –

答えて

0

すぎて、(...、 "シート3"、 "シート4")

Set nextrow = Worksheets("Sheet6").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) 

と同類で

Set nextrow = Sheet6.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) 

を代入してみてください。

関連する問題