Trabajar con Fechas
Buenos días por favor necesito que me aclaren que tengo malo en mi rutina, resulta que el modulo hace los siguiente: Solicito 5 datos: Obra, Semana, Desde, Hasta, Nº Maquina, los repito para los siete días de la semana introducida y luego en la columna 6 desgloso esos días es decir si la fecha introducida es Desde:25/02/09 Hasta: 03/03/09, es desglose seria: 25 - 26 - 27 - 28 - 1 - 2 - 3, pero la rutina me hace el desglose de la siguiente manera: 25 - 26 - 27 - 28 - 29 - 30 -31, no respeta el mes que es de 28 días y así pasa cuando el mes trae 30 días, cuando la semana cae justo en 31 si lo hace bien. Ayuda por favor... Mi modulo es la siguiente
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim fila, fila2, var As Integer
fila = 9
fila2 = 9
While Cells(fila, 6) <> Empty
fila = fila + 1
Wend
Cells(fila, 1) = UCase(TextBox1)
Cells(fila, 2) = TextBox2
Cells(fila, 3) = CDate(TextBox3)
Cells(fila, 4) = CDate(TextBox4)
Cells(fila, 5) = TextBox5
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox5 = Empty
Worksheets("Control").Cells(fila, 6).Formula = "=Day(C" & fila & ")"
fecha = Worksheets("Control").Cells(fila, 3).Value
Mes = Month(fecha)
Rem AQUI SE REPITEN LOS DATOS
For counter = 1 To 6
Worksheets("Control").Cells(fila + 1, 1).Value = Worksheets("Control").Cells(fila, 1).Value
Worksheets("Control").Cells(fila + 1, 2).Value = Worksheets("Control").Cells(fila, 2).Value
Worksheets("Control").Cells(fila + 1, 3).Value = Worksheets("Control").Cells(fila, 3).Value
Worksheets("Control").Cells(fila + 1, 4).Value = Worksheets("Control").Cells(fila, 4).Value
Worksheets("Control").Cells(fila + 1, 5).Value = Worksheets("Control").Cells(fila, 5).Value
If Mes = "1" Or "3" Or "5" Or "7" Or "8" Or "10" Or "12" Then
If Worksheets("Control").Cells(fila, 6).Value = 31 Then
Worksheets("Control").Cells(fila + 2, 6).Value = var + 1
var = var + 1
Else
Worksheets("Control").Cells(fila + 1, 6).Value = Worksheets("Control").Cells(fila, 6).Value + 1
End If
Else
If Mes = "4" Or "6" Or "9" Or "11" Then
var = 0
If Worksheets("Control").Cells(fila, 6).Value = 30 Then
Worksheets("Control").Cells(fila + 1, 6).Value = var + 1
var = var + 1
Else
Worksheets("Control").Cells(fila + 1, 6).Value = Worksheets("Control").Cells(fila, 6).Value + 1
End If
Else
If Mes = "2" Then
If Worksheets("Control").Cells(fila, 6).Value = 28 Then
Worksheets("Control").Cells(fila + 1, 6).Value = var + 1
var = var + 1
Else
Worksheets("Control").Cells(fila + 1, 6).Value = Worksheets("Control").Cells(fila, 6).Value + 1
End If
End If
End If
End If
fila = fila + 1
fila2 = fila2 + 1
Next counter
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Unload Datos1
Consumo.Show
End Sub
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim fila, fila2, var As Integer
fila = 9
fila2 = 9
While Cells(fila, 6) <> Empty
fila = fila + 1
Wend
Cells(fila, 1) = UCase(TextBox1)
Cells(fila, 2) = TextBox2
Cells(fila, 3) = CDate(TextBox3)
Cells(fila, 4) = CDate(TextBox4)
Cells(fila, 5) = TextBox5
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox5 = Empty
Worksheets("Control").Cells(fila, 6).Formula = "=Day(C" & fila & ")"
fecha = Worksheets("Control").Cells(fila, 3).Value
Mes = Month(fecha)
Rem AQUI SE REPITEN LOS DATOS
For counter = 1 To 6
Worksheets("Control").Cells(fila + 1, 1).Value = Worksheets("Control").Cells(fila, 1).Value
Worksheets("Control").Cells(fila + 1, 2).Value = Worksheets("Control").Cells(fila, 2).Value
Worksheets("Control").Cells(fila + 1, 3).Value = Worksheets("Control").Cells(fila, 3).Value
Worksheets("Control").Cells(fila + 1, 4).Value = Worksheets("Control").Cells(fila, 4).Value
Worksheets("Control").Cells(fila + 1, 5).Value = Worksheets("Control").Cells(fila, 5).Value
If Mes = "1" Or "3" Or "5" Or "7" Or "8" Or "10" Or "12" Then
If Worksheets("Control").Cells(fila, 6).Value = 31 Then
Worksheets("Control").Cells(fila + 2, 6).Value = var + 1
var = var + 1
Else
Worksheets("Control").Cells(fila + 1, 6).Value = Worksheets("Control").Cells(fila, 6).Value + 1
End If
Else
If Mes = "4" Or "6" Or "9" Or "11" Then
var = 0
If Worksheets("Control").Cells(fila, 6).Value = 30 Then
Worksheets("Control").Cells(fila + 1, 6).Value = var + 1
var = var + 1
Else
Worksheets("Control").Cells(fila + 1, 6).Value = Worksheets("Control").Cells(fila, 6).Value + 1
End If
Else
If Mes = "2" Then
If Worksheets("Control").Cells(fila, 6).Value = 28 Then
Worksheets("Control").Cells(fila + 1, 6).Value = var + 1
var = var + 1
Else
Worksheets("Control").Cells(fila + 1, 6).Value = Worksheets("Control").Cells(fila, 6).Value + 1
End If
End If
End If
End If
fila = fila + 1
fila2 = fila2 + 1
Next counter
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Unload Datos1
Consumo.Show
End Sub
1 respuesta
Respuesta de caranbis
1