Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/08/2012, 12:39
aibarchin1
 
Fecha de Ingreso: agosto-2012
Mensajes: 1
Antigüedad: 11 años, 8 meses
Puntos: 0
registrar mercancia y actualizar nueva VBA excel

Les escribo para consultarles sobre un tema que me tiene preocupado.
Hace unos días cree un código para que desde un userform excel me buscara
una referencia en una hoja y le sumara una cantidad, el problema con el que me
encuentro es que si la referencia no existe, automáticamente me da error 91
y el depurador me lleva a este punto

Private Sub referencia_change()

Application. ScreenUpdating = False

Sheets("STOCK"). Activate

Range("a1:a50000"). Select


Producto_existente = Cells. Find(What:=referencia, After:=ActiveCell, LookIn:=xlValues, _

LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _

MatchCase:=True). Activate



If producto_existente = True Then


Categoría. Value = ActiveCell. Offset(0, 1). Value

Modelo. Value = ActiveCell. Offset(0, 2). Value

Precio. Value = ActiveCell. Offset(0, 4). Value

Stock. Value = ActiveCell. Offset(0, 5). Value

Detalles. Value = ActiveCell. Offset(0, 3). Value

End If



Application. ScreenUpdating = True

End Sub

Private Sub CommandButton1_Click()


Application. ScreenUpdating = False

Dim valor As Integer

Dim iFila As Long

Dim ws As Worksheet

Set ws = Worksheets(1)


IFila = ws. Cells(Rows. Count, 1) _

. End(xlUp). Offset(1, 0). Row


If Me.referencia.Value = "" Then

Me.referencia.SetFocus

MsgBox "Debe ingresar un nombre"

Exit Sub

End If


If Me. Cantidad = "" Then

MsgBox "No ha indicado la cantidad"

Exit Sub

End If


Valor = Val(stock. Value) + Val(cantidad. Value)


MsgBox "El stock actual del producto " & referencia & " es de " & valor

Sheets("stock"). Activate

ActiveCell. Offset(0, 5) = valor

Sheets("stock"). Activate


Ws. Cells(iFila, 1). Value = referencia. Value

Ws. Cells(iFila, 2). Value = categoría. Value

Ws. Cells(iFila, 3). Value = modelo. Value

Ws. Cells(iFila, 4). Value = detalles. Value

Ws. Cells(iFila, 5). Value = precio. Value

Ws. Cells(iFila, 6). Value = cantidad. Value








Me.referencia.Value = ""

Me. Categoría. Value = ""

Me.modelo.Value = ""

Me.detalles.Value = ""

Me.precio.Value = ""

Me. Cantidad = ""



Me.referencia.SetFocus


Application. ScreenUpdating = True


End Sub





Private Sub UserForm_Click()


End Sub


me podría ayudar para que al introducir una referencia no existente me la creara en la hoja STOCK y si es existente la encontrara y le sumara la cantidad añadida?

Muchas Gracias por su ayuda!