使用基于用户表单输入的新值替换旧值

时间:2016-04-04 03:23:31

标签: vba userform

我目前遇到运行时错误'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"

1 个答案:

答案 0 :(得分:0)

尝试替换

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

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

和喜欢(“Sheet3”,“Sheet4”,......)。