Dependiendo el valor de un textbox, mandar info a una u otra hoja (vba excel)
Tengo este código, también dejo una imagen:
Dim Fila As Long
Dim Final As Long
Dim Fila1 As Long
Dim Final1 As Long
Set h1 = Sheets("ENTRADAS")
Set h2 = Sheets("SALIDAS")
'Determina el final del listado de productos
Final = GetNuevoR(Hoja3)
'AÑADIMOS LA INFO A SU HOJA CORRESPONDIENTE
If txt_diferencia.Value > 0 Then
For Fila = 2 To Final
Hoja7.Range("D3").Value = Hoja7.Range("D3").Value + 1
Hoja7.Range("D12").Value = Hoja7.Range("D12").Value + 1
h1.Cells(Final, 1) = Hoja7.Range("D3")
h1.Cells(Final, 2) = Date
h1.Cells(Final, 8) = Hoja7.Range("D12")
h1.Cells(Final, 9) = "CONSOLIDAR"
h1.Cells(Final, 12) = Me.txt_codigo
h1.Cells(Final, 13) = Me.txt_nombre
h1.Cells(Final, 14) = Me.txt_diferencia
Next
ElseIf txt_diferencia.Value < 0 Then
For Fila1 = 2 To Final1
Hoja7.Range("F3").Value = Hoja7.Range("F3").Value + 1
Hoja7.Range("F18").Value = Hoja7.Range("F18").Value + 1
h2.Cells(Final1, 1) = Hoja7.Range("F3")
h2.Cells(Final1, 2) = Date
h2.Cells(Final1, 15) = Hoja7.Range("F18")
h2.Cells(Final1, 16) = "CONSOLIDAR"
h2.Cells(Final1, 17) = Me.txt_codigo
h2.Cells(Final1, 18) = Me.txt_nombre
h2.Cells(Final1, 19) = Me.txt_diferencia
Next
End If
txt_stock.Value = txt_stock_fisico.Value
txt_stock_fisico = ""
txt_diferencia = ""
MsgBox " Stock actualizado", vbInformation, ""
txt_codigo.Enabled = False
txt_nombre.Enabled = True
txt_ubicacion.Enabled = True
txt_compra.Enabled = True
txt_venta.Enabled = True
txt_stock.Enabled = False
txt_stock_fisico.Enabled = False
txt_diferencia.Enabled = False
lb_consolidar_activar.Visible = True
lb_consolidar_activar.Enabled = True
lb_consolidar_aceptar.Visible = False
lb_consolidar_cancelar.Enabled = False
lb_modificar.Enabled = True
lb_volver.Enabled = True
txt_nombre.SetFocus

Si, la diferencia es positiva, el código me funciona.
Pero si es negativa el código no hace nada.
¿Alguna sugerencia?
1 respuesta
Respuesta de Carlos Arrocha
1