You are on page 1of 6

Sub Macro2()

Dim Vent As Integer, Ped As Integer, Costcomp As Long, ing As Long


Dim Remb As Integer, Ingremb As Long, Perd As Integer
Dim Costperd As Long, Util As Long
'Aplicacion de la tecnia de montecarlo
Dim Rango1 As Range
Set Rango1 = Worksheets(2).Range("$C$6:$E$11")
Range("H7:P36").ClearContents
Cells(7, 8).Value = 20
Cells(7, 14).Value = 3
For i = 8 To 37
R = Rnd
Cells(i, 7).Value
N = Cells(i, 7).Value
Cells(i, 8).Value = Vlookup(N, Rango1, 3)
Next i
For J = 8 To 37
Vent = Cells(J, 8).Value
Ped = Cells(J, 9).Value
Costcomp = Cells(J, 10).Value
ing = Cells(J, 11).Value
Remb = Cells(J, 12).Value
Ingremb = Cells(J, 13).Value
Perd = Cells(J, 14).Value
Costperd = Cells(J, 15).Value
Util = Cells(J, 16).Value
'calculo de pedido
Ped = Cells(J - 1, 8).Value + Cells(J - 1, 14).Value
Cells(J, 9).Value = Ped
'Calculo del costo de compra

Costcomp = Ped * Cells(12, 3).Value


Cells(J, 10).Value = Costcomp
'Calculo del Ingreso
If Vent >= Ped Then
ing = Ped * Cells(13, 3).Value
Cells(J, 11).Value = ing
Perd = Vent - Ped
Remb = 0
Cells(J, 12).Value = Remb
Ingremb = 0
Cells(J, 13).Value = Ingremb
'Calculo de la perdida
Cells(J, 14).Value = Perd
Costperd = Perd * Cells(15, 3).Value
Cells(J, 15).Value = Costperd
Else
ing = Vent * Cells(13, 3).Value
Cells(J, 11).Value = ing
Remb = Ped - Vent
Cells(J, 12).Value = Remb
Ingremb = Remb * Cells(14, 3).Value
Cells(J, 13).Value = Ingremb
Perd = 0
Cells(J, 14).Value = Perd
Costperd = 0
Cells(J, 15).Value = Costperd
End If
'Calculo de la utilidad
Util = ing - Costcomp + Imgremb - Costperd
Cells(J, 16).Value = Util

Next j
Range("J37").Formula = "=Average(J7:J36)"
End Sub
Function Vlookup(N As Variant, Rango1 As Range, c As Integer) As Integer
Vlookup = Excel.WorksheetFunction.Vlookup(N, Rango1, c)
End Function

Sub Macro4()
Private Sub CommandButton1_Click()
Dim TE As Integer, PRO As Integer, M As Variant, M2 As Variant, S2 As Variant
Dim FINAL As Integer, S As Variant, Sd As Double, Sd2 As Double
M = Cells(3, 7).Value
S = Cells(4, 7).Value
PRO = Cells(3, 11)
Range("S6:U35").ClearContents
REP = InputBox("Digite el nmero de Replicas (No mayor que 30):", "NUMERO
DE REPLICAS")
If (REP > 30) Then
MsgBox "El nmero de replicas excede a la capacidad de corridas", vbOKOnly, "
!! LO SIENTO!!"
Exit Sub
End If
For i = 1 To REP
'Limpipeza
Range("H6:P29").ClearContents

Range("k4").ClearContents
Range("N4").ClearContents
For J = 6 To 29
Cells(J, 8).Value = Rnd
Cells(J, 15).Value = 0
Next J
'Generacin de la demanda
For h = 6 To 29
N = Cells(h, 8).Value
D = Round(NORMAL(N, M, S), 0)
Cells(h, 9).Value = D
Next h
M2 = Cells(5, 3).Value
S2 = Cells(5, 5).Value
Sum = 0
'Generacin de los tiempos de entrega
For k = 10 To 19
Cells(k, 2).Value Rnd
N2 = Cells(k, 2).Value
Cells(k, 3).Value = Round(NORMAL(N2, M2, S2), 0)
Next k
'Desviacin estandar durante el tiempo de entrega
Sd2 = Sqr(M2 * (S) ^ 2 + M * (S2) ^ 2)
Cells(4, 14).Value = Sd2
'Probabilidad de que haya existencias
Range("K4").Formula = "=Normdist(K3,G3,N4,1)"
J = 10
cont = 0
Cells(6, 10).Value = Cells(2, 11).Value
For x = 6 To 29

II = Celss(x, 10).Value
D = Cells(x, 9).Value
Q = Cells(x, 11).Value
FINAL = Cells(x, 13).Value
FALT = Cells(x, 13).Value
FINAL = II + Q + FALT - D
If (FINAL <= 50) And (TE <= 0) Then
cont = cont + 1
Cells(x, 14).Value = 1
Cells(x, 15).Value = cont
Cells(x, 16).Value = Cells(J, 3).Value
J=J+1
TE = Cells(x, 16).Value
If (x + (TE + 1)) <= 29 Then
Cells(x + TE, 11).Value -Cells(2, 7).Value
End If
Else
Cells(x, 14).Value = 0
End If
If (FINAL <= 0) Then
Cells(x, 12).Value = 0
Cells(x, 13).Value = FINAL * (-1)
Cells(x + 1, 10).Value = FINAL
Else
Cells(x, 12).Value = FINAL
Cells(x + 1, 10).Value = Cells(x, 12).Value
Cells(x, 13).Value = 0
End If
TE = TE - 1
Cells(30, 10).Value = ""

Next x
Cells(i + 5, 19).Value = Cells(31, 14)
Cells(i + 5, 20).Value = Cells(31, 12)
Cells(i + 5, 21).Value = Cells(31, 13)
Var = "REPLICA NUMERO " + Str(i)
MsgBox Var, vbKOnly, "REPLICAS"
Next i
Range("S36").Formula = "=average(S6:S35)"
Range("T36").Formula = "=average(T6:T35)"
Range("U36").Formula = "=average(U6:U35)"
Range("C7").Formula = "=1-(U36/G2)"

End Sub

Function NORMAL(N As Variant, M As Variant, S As Variant) As Double


NORMAL = Excel.WorksheetFunction.NormInv(N, M, S)
End Function

End Function

You might also like