Ayuda con variables doubles
Hola, espero puedan ayudarme con una variables de macros en excel. Tengo una macro de Control de existencias. Funciona bien pero con unidades en decimales no. No he podido ponerle un double al codigo para que me agregue con la funcion: ActiveCell.Offset(0, 3).Value = ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value lo que le ingreso como 11,5 or ejemplo.
Este es el codigo completo:
Sub ControldeInventario()
Application.ScreenUpdating = False
If ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_FECHA").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_PROVEEDOR").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_SUCURSAL").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_PRECIO").RefersToRange.Value = Empty Then
MsgBox "Favor de completar los datos", vbOKOnly + vbInformation, "**Información incompleta"
Exit Sub
End If
Worksheets("INVENTARIO").Select
Range("A:A").Select
For x = 1 To 20
Selection.Find(What:=ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value, _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
validacion = Len(ActiveCell.Text)
If Len(ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value) = validacion Then
ActiveCell.Select
Exit For
End If
Next x
If ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value _
And ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Text = "ENTRADA" Then
ActiveCell.Offset(0, 3).Select
bodegaanterior = ActiveCell.Value
bodeganueva = Val(ActiveCell.Value) + Val(ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value)
ActiveCell.Value = bodeganueva
Selection.End(xlToLeft).Select
Worksheets("PRINCIPAL").Select
MsgBox "Se agregaron " & ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value _
& " " & ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Text _
& " a bodega." & Chr(13) & "Aumentó de: " & bodegaanterior & " a " & bodeganueva _
& " artículos.", vbOKOnly + vbInformation, "**Entradas"
Worksheets("HISTORIAL").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value
ActiveCell.Offset(0, 1).Value = ThisWorkbook.Names("RNG_CATEGORIA").RefersToRange.Value
ActiveCell.Offset(0, 2).Value = ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Value
ActiveCell.Offset(0, 3).Value = ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value
ActiveCell.Offset(0, 4).Value = ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value
ActiveCell.Offset(0, 5).Value = ThisWorkbook.Names("RNG_FECHA").RefersToRange.Value
ActiveCell.Offset(0, 6).Value = ThisWorkbook.Names("RNG_PROVEEDOR").RefersToRange.Value
ActiveCell.Offset(0, 7).Value = ThisWorkbook.Names("RNG_PRECIO").RefersToRange.Value
ActiveCell.Offset(0, 8).Value = ThisWorkbook.Names("RNG_SUCURSAL").RefersToRange.Value
Worksheets("PRINCIPAL").Select
MsgBox "Registro exitoso en historial", vbOKOnly + vbInformation, "**Historial"
Range("D5").ClearContents
Range("A1").Select
End If
If ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value _
And ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value = "SALIDA" Then
ActiveCell.Offset(0, 3).Select
bodegaanterior = ActiveCell.Value
If bodegaanterior < ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value Then
MsgBox "No hay artículos suficientes" & Chr(13) & "Sólo hay " & bodegaanterior & " artículos en bodega.", vbOKOnly + vbCritical, "**Información de bodega"
Sheets("PRINCIPAL").Select
Exit Sub
End If
bodeganueva = Val(ActiveCell.Value) - Val(ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value)
ActiveCell.Value = bodeganueva
Selection.End(xlToLeft).Select
Worksheets("PRINCIPAL").Select
MsgBox "Salieron " & ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value _
& " " & ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Value & " de bodega." _
& Chr(13) & "Disminuyó de: " & bodegaanterior & " a " & bodeganueva & " artículos.", _
vbOKOnly + vbInformation, "**Salidas"
Sheets("HISTORIAL").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value
ActiveCell.Offset(0, 1).Value = ThisWorkbook.Names("RNG_CATEGORIA").RefersToRange.Value
ActiveCell.Offset(0, 2).Value = ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Value
ActiveCell.Offset(0, 3).Value = ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value
ActiveCell.Offset(0, 4).Value = ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value
ActiveCell.Offset(0, 5).Value = ThisWorkbook.Names("RNG_FECHA").RefersToRange.Value
ActiveCell.Offset(0, 6).Value =...
Este es el codigo completo:
Sub ControldeInventario()
Application.ScreenUpdating = False
If ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_FECHA").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_PROVEEDOR").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_SUCURSAL").RefersToRange.Value = Empty Or _
ThisWorkbook.Names("RNG_PRECIO").RefersToRange.Value = Empty Then
MsgBox "Favor de completar los datos", vbOKOnly + vbInformation, "**Información incompleta"
Exit Sub
End If
Worksheets("INVENTARIO").Select
Range("A:A").Select
For x = 1 To 20
Selection.Find(What:=ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value, _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
validacion = Len(ActiveCell.Text)
If Len(ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value) = validacion Then
ActiveCell.Select
Exit For
End If
Next x
If ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value _
And ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Text = "ENTRADA" Then
ActiveCell.Offset(0, 3).Select
bodegaanterior = ActiveCell.Value
bodeganueva = Val(ActiveCell.Value) + Val(ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value)
ActiveCell.Value = bodeganueva
Selection.End(xlToLeft).Select
Worksheets("PRINCIPAL").Select
MsgBox "Se agregaron " & ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value _
& " " & ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Text _
& " a bodega." & Chr(13) & "Aumentó de: " & bodegaanterior & " a " & bodeganueva _
& " artículos.", vbOKOnly + vbInformation, "**Entradas"
Worksheets("HISTORIAL").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value
ActiveCell.Offset(0, 1).Value = ThisWorkbook.Names("RNG_CATEGORIA").RefersToRange.Value
ActiveCell.Offset(0, 2).Value = ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Value
ActiveCell.Offset(0, 3).Value = ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value
ActiveCell.Offset(0, 4).Value = ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value
ActiveCell.Offset(0, 5).Value = ThisWorkbook.Names("RNG_FECHA").RefersToRange.Value
ActiveCell.Offset(0, 6).Value = ThisWorkbook.Names("RNG_PROVEEDOR").RefersToRange.Value
ActiveCell.Offset(0, 7).Value = ThisWorkbook.Names("RNG_PRECIO").RefersToRange.Value
ActiveCell.Offset(0, 8).Value = ThisWorkbook.Names("RNG_SUCURSAL").RefersToRange.Value
Worksheets("PRINCIPAL").Select
MsgBox "Registro exitoso en historial", vbOKOnly + vbInformation, "**Historial"
Range("D5").ClearContents
Range("A1").Select
End If
If ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value _
And ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value = "SALIDA" Then
ActiveCell.Offset(0, 3).Select
bodegaanterior = ActiveCell.Value
If bodegaanterior < ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value Then
MsgBox "No hay artículos suficientes" & Chr(13) & "Sólo hay " & bodegaanterior & " artículos en bodega.", vbOKOnly + vbCritical, "**Información de bodega"
Sheets("PRINCIPAL").Select
Exit Sub
End If
bodeganueva = Val(ActiveCell.Value) - Val(ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value)
ActiveCell.Value = bodeganueva
Selection.End(xlToLeft).Select
Worksheets("PRINCIPAL").Select
MsgBox "Salieron " & ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value _
& " " & ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Value & " de bodega." _
& Chr(13) & "Disminuyó de: " & bodegaanterior & " a " & bodeganueva & " artículos.", _
vbOKOnly + vbInformation, "**Salidas"
Sheets("HISTORIAL").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = ThisWorkbook.Names("RNG_ID_ARTICULO").RefersToRange.Value
ActiveCell.Offset(0, 1).Value = ThisWorkbook.Names("RNG_CATEGORIA").RefersToRange.Value
ActiveCell.Offset(0, 2).Value = ThisWorkbook.Names("RNG_DESCRIPCION").RefersToRange.Value
ActiveCell.Offset(0, 3).Value = ThisWorkbook.Names("RNG_CANTIDAD").RefersToRange.Value
ActiveCell.Offset(0, 4).Value = ThisWorkbook.Names("RNG_CONTROL_BODEGA").RefersToRange.Value
ActiveCell.Offset(0, 5).Value = ThisWorkbook.Names("RNG_FECHA").RefersToRange.Value
ActiveCell.Offset(0, 6).Value =...
1 respuesta
Respuesta de Carlos Serrano