Soy nuevo en esto y me gustaría que revisaran el codigo y me dijeran los errores que ven, grax y saludos.
Sub Replanificar()
Dim n, m, inv, pedido, oc, consumo, mes As Integer
Dim fecha As Long
' Los meses estan en numero, el mes 1 corresponde a enero 2014, meses anteriores disminuye uno por mes
n = 2 'n es el el renglon de oc
m = 2 'm es el renglon de la ov
While Sheets("Hoja1").Cells(n, "A") <> ""
inv = Sheets("Hoja1").Cells(n, "B")
consumo = Sheets("Hoja1").Cells(n, "D") + Sheets("Hoja1").Cells(n, "F") + Sheets("Hoja1").Cells(n, "G") + Sheets("Hoja1").Cells(n, "H") + Sheets("Hoja1").Cells(n, "I") + Sheets("Hoja1").Cells(n, "J")
oc = Sheets("Hoja1").Cells(n, "C")
If inv > consumo Then 'estos conjuntosde if se quese pueden reducir con uno de ciclos, lo tengo como pendiente
If inv > (consumo + Sheets("Hoja1").Cells(n, "J")) Then
consumo = consumo + Sheets("Hoja1").Cells(n, "J")
If inv > consumo + Sheets("Hoja1").Cells(n, "K") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "K")
If inv > consumo + Sheets("Hoja1").Cells(n, "L") Then
consumo = consumoe + Sheets("Hoja1").Cells(n, "L")
If inv > consumo + Sheets("Hoja1").Cells(n, "M") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "M")
If inv > consumo + Sheets("Hoja1").Cells(n, "N") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "N")
If inv > consumo + Sheets("Hoja1").Cells(n, "O") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "O")
If inv > consumo + Sheets("Hoja1").Cells(n, "P") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "P")
If inv > consumo + Sheets("Hoja1").Cells(n, "Q") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "Q")
If inv > consumo + Sheets("Hoja1").Cells(n, "R") Then
consumo = consumoe + Sheets("Hoja1").Cells(n, "R")
If inv > consumo + Sheets("Hoja1").Cells(n, "S") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "S")
If inv > consumo + Sheets("Hoja1").Cells(n, "T") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "T")
If inv > consbase + Sheets("Hoja1").Cells(n, "U") Then
pedido = oc
fecha = 1122014
Sheets("Hoja2").Cells(m, "D") = pedido
Sheets("Hoja2").Cells(m, "E") = fecha
Sheets("Hoja2").Cells(m, "C") = Sheets("Hoja1").Cells(n, "A")
m = m + 1
Else
mes = 9
planificacion (consumo)
End If
Else
mes = 8
planificacion (consumo)
End If
Else
mes = 7
planificacion (consumo)
End If
Else
mes = 6
planificacion (consumo)
End If
Else
mes = 5
planificacion (consumo)
End If
Else
mes = 4
planificacion (consumo)
End If
Else
mes = 3
planificacion (consumo)
End If
Else
mes = 2
planificacion (consumo)
End If
Else
mes = 1
planificacion (consumo)
End If
Else
mes = -0
planificacion (consumo)
End If
Else
mes = -1
planificacion (consumo)
End If
Else
mes = -2
planificacion (consumo)
End If
Else
mes = -2
planificacion (consumo) 'como es el codigo para enviar las variables consumo, mes, oc??
End If
n = n + 1
Wend
MsgBox "area concluida!", 0, "Estado"
End Sub
Sub planificacion(consumo) 'como es el codigo para enviar las variables consumo, mes, oc??
Dim mes, i As Integer
Dim fecha As Long
Dim k As String
i = 1
While oc >= 0
If i = 1 Then
If oc >= consumo Then
pedido = consumo
Else
pedido = oc
End If
i = 0
Else
If oc >= Sheets("Hoja2").Cells(n, k) Then
pedido = Sheets("Hoja2").Cells(n, k)
fecha = mes
Else
pedido = oc
End If
End If
Select Case mes
Case -2
fecha = 26092013
Case -1
fecha = 23102013
Case 0
fecha = 27112013
Case 1
fecha = 25122013
Case 2
fecha = 29012014
Case 3
fecha = 26022014
Case 4
fecha = 26032014
Case 5
fecha = 23042014
Case 6
fecha = 28052014
Case 7
fecha = 25062014
Case 8
fecha = 23072014
Case 9
fecha = 27082014
Case Else
fecha = 0
End Select
Sheets("Hoja2").Cells(m, "D") = pedido 'aparece error en estas celdas
Sheets("Hoja2").Cells(m, "E") = fecha
Sheets("Hoja2").Cells(m, "C") = Sheets("Hoja1").Cells(n, "A")
Sheets("Hoja2").Cells(m, "A") = mes
oc = oc - pedido
mes = mes + 1
m = m + 1
k = k + 1
Wend
End Sub
Ya corregí el error. Grax y cierren hilo. Saludos.
Sub Replanificar()
Dim n, m, inv, pedido, oc, consumo, mes As Integer
Dim fecha As Long
' Los meses estan en numero, el mes 1 corresponde a enero 2014, meses anteriores disminuye uno por mes
n = 2 'n es el el renglon de oc
m = 2 'm es el renglon de la ov
While Sheets("Hoja1").Cells(n, "A") <> ""
inv = Sheets("Hoja1").Cells(n, "B")
consumo = Sheets("Hoja1").Cells(n, "D") + Sheets("Hoja1").Cells(n, "F") + Sheets("Hoja1").Cells(n, "G") + Sheets("Hoja1").Cells(n, "H") + Sheets("Hoja1").Cells(n, "I") + Sheets("Hoja1").Cells(n, "J")
oc = Sheets("Hoja1").Cells(n, "C")
If inv > consumo Then 'estos conjuntosde if se quese pueden reducir con uno de ciclos, lo tengo como pendiente
If inv > (consumo + Sheets("Hoja1").Cells(n, "J")) Then
consumo = consumo + Sheets("Hoja1").Cells(n, "J")
If inv > consumo + Sheets("Hoja1").Cells(n, "K") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "K")
If inv > consumo + Sheets("Hoja1").Cells(n, "L") Then
consumo = consumoe + Sheets("Hoja1").Cells(n, "L")
If inv > consumo + Sheets("Hoja1").Cells(n, "M") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "M")
If inv > consumo + Sheets("Hoja1").Cells(n, "N") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "N")
If inv > consumo + Sheets("Hoja1").Cells(n, "O") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "O")
If inv > consumo + Sheets("Hoja1").Cells(n, "P") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "P")
If inv > consumo + Sheets("Hoja1").Cells(n, "Q") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "Q")
If inv > consumo + Sheets("Hoja1").Cells(n, "R") Then
consumo = consumoe + Sheets("Hoja1").Cells(n, "R")
If inv > consumo + Sheets("Hoja1").Cells(n, "S") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "S")
If inv > consumo + Sheets("Hoja1").Cells(n, "T") Then
consumo = consumo + Sheets("Hoja1").Cells(n, "T")
If inv > consbase + Sheets("Hoja1").Cells(n, "U") Then
pedido = oc
fecha = 1122014
Sheets("Hoja2").Cells(m, "D") = pedido
Sheets("Hoja2").Cells(m, "E") = fecha
Sheets("Hoja2").Cells(m, "C") = Sheets("Hoja1").Cells(n, "A")
m = m + 1
Else
mes = 9
planificacion (consumo)
End If
Else
mes = 8
planificacion (consumo)
End If
Else
mes = 7
planificacion (consumo)
End If
Else
mes = 6
planificacion (consumo)
End If
Else
mes = 5
planificacion (consumo)
End If
Else
mes = 4
planificacion (consumo)
End If
Else
mes = 3
planificacion (consumo)
End If
Else
mes = 2
planificacion (consumo)
End If
Else
mes = 1
planificacion (consumo)
End If
Else
mes = -0
planificacion (consumo)
End If
Else
mes = -1
planificacion (consumo)
End If
Else
mes = -2
planificacion (consumo)
End If
Else
mes = -2
planificacion (consumo) 'como es el codigo para enviar las variables consumo, mes, oc??
End If
n = n + 1
Wend
MsgBox "area concluida!", 0, "Estado"
End Sub
Sub planificacion(consumo) 'como es el codigo para enviar las variables consumo, mes, oc??
Dim mes, i As Integer
Dim fecha As Long
Dim k As String
i = 1
While oc >= 0
If i = 1 Then
If oc >= consumo Then
pedido = consumo
Else
pedido = oc
End If
i = 0
Else
If oc >= Sheets("Hoja2").Cells(n, k) Then
pedido = Sheets("Hoja2").Cells(n, k)
fecha = mes
Else
pedido = oc
End If
End If
Select Case mes
Case -2
fecha = 26092013
Case -1
fecha = 23102013
Case 0
fecha = 27112013
Case 1
fecha = 25122013
Case 2
fecha = 29012014
Case 3
fecha = 26022014
Case 4
fecha = 26032014
Case 5
fecha = 23042014
Case 6
fecha = 28052014
Case 7
fecha = 25062014
Case 8
fecha = 23072014
Case 9
fecha = 27082014
Case Else
fecha = 0
End Select
Sheets("Hoja2").Cells(m, "D") = pedido 'aparece error en estas celdas
Sheets("Hoja2").Cells(m, "E") = fecha
Sheets("Hoja2").Cells(m, "C") = Sheets("Hoja1").Cells(n, "A")
Sheets("Hoja2").Cells(m, "A") = mes
oc = oc - pedido
mes = mes + 1
m = m + 1
k = k + 1
Wend
End Sub
Ya corregí el error. Grax y cierren hilo. Saludos.