Dim Orden_Factu As Variant
Dim Factura, IVA, ValorIVA, ValorSIVA As Variant
Dim RProducto As Range
Dim Rango_Factura As Range
Private Sub CommandButton1_Click()
Dim ordennum As String
'Item a anexar en Facturacion Order
OrderRow = Sheets("FacturacionOrder").Cells(Rows.Count, 1).End(xlUp).Row
OrderRow1 = OrderRow + 1
'Items
Order = Sheets("TBL_ProductoOrden").Cells(Rows.Count, 1).End(xlUp).Row
Order1 = Order + 1
Set RProducto = Sheets("TBL_Productos").Range("b:H")
Set Rango_Factura = Sheets("FacturacionOrder").Range("A:A")
'Extraccion
For x = 2 To Order
ordennum = Orden_Fact.TextBox1
p = Sheets("TBL_ProductoOrden").Cells(x, 1)
Y = Sheets("TBL_ProductoOrden").Cells(x, 2)
Z = Sheets("TBL_ProductoOrden").Cells(x, 5)
on Error Goto Falta
Orden_Factu = Application.WorksheetFunction.VLookup(p, Rango_Factura, 1, 0)
On Error Goto 0
If Y = ordennum And Z = True Then
If p = Orden_Factu Then
Else
OrderRow = Sheets("FacturacionOrder").Cells(Rows.Count, 1).End(xlUp).Row
OrderRow1 = OrderRow + 1
Sheets("FacturacionOrder").Cells(OrderRow1, 1) = Sheets("TBL_ProductoOrden").Cells(x, 1)
Sheets("FacturacionOrder").Cells(OrderRow1, 2) = Sheets("TBL_ProductoOrden").Cells(x, 2)
Sheets("FacturacionOrder").Cells(OrderRow1, 3) = Sheets("TBL_ProductoOrden").Cells(x, 3)
Sheets("FacturacionOrder").Cells(OrderRow1, 4) = Sheets("TBL_ProductoOrden").Cells(x, 4)
Sheets("FacturacionOrder").Cells(OrderRow1, 5) = Sheets("TBL_ProductoOrden").Cells(x, 5)
Factura = Application.WorksheetFunction.VLookup(Sheets("TBL_ProductoOrden").Cells(x, 3), RProducto, 6, 0)
IVA = Application.WorksheetFunction.VLookup(Sheets("TBL_ProductoOrden").Cells(x, 3), RProducto, 4, 0)
ValorIVA = Application.WorksheetFunction.VLookup(Sheets("TBL_ProductoOrden").Cells(x, 3), RProducto, 5, 0)
ValorSIVA = Application.WorksheetFunction.VLookup(Sheets("TBL_ProductoOrden").Cells(x, 3), RProducto, 3, 0)
Sheets("FacturacionOrder").Cells(OrderRow1, 6) = Factura
Sheets("FacturacionOrder").Cells(OrderRow1, 7) = IVA
Sheets("FacturacionOrder").Cells(OrderRow1, 8) = ValorIVA * Sheets("FacturacionOrder").Cells(OrderRow1, 4)
Sheets("FacturacionOrder").Cells(OrderRow1, 9) = ValorSIVA * Sheets("FacturacionOrder").Cells(OrderRow1, 4)
End If
Else
End If
Next x
exit Sub
Falta:
orden_Facto=0: resume Next
End Sub