You are on page 1of 5

Dim registro(1 To 3000, 1 To 3000), sregistroSEMANAS(1 To 3000, 1 To 3000) As Single

Dim materiales01(1 To 3000, 1 To 3000), materiales02(1 To 3000, 1 To 3000), rendimientos(1


To 3000, 1 To 3000) As Single
Dim materiales03(1 To 3000, 1 To 3000), materiales04(1 To 3000, 1 To 3000) As Single

Dim borrador(1 To 3000), sregistro(1 To 3000), diassemana(1 To 3000) As Single


Dim ndatos, nitems, nmateriales As Integer
diassemana(1) = 0
diassemana(2) = 12
diassemana(3) = 31
diassemana(4) = 53
diassemana(5) = 66
Dim i, j, k, l As Integer

ndatos = Val(Cells(1, 1))


nmateriales = 19

For i = 1 To ndatos
registro(i, 1) = CDbl((Cells(i + 3, 4)))
registro(i, 2) = CDbl(Cells(i + 3, 10)) ' COLUMNA J
borrador(i) = registro(i, 1)
For j = 1 To nmateriales
If (Cells(i + 3, 12 + j)) = "" Or (Cells(i + 3, 12 + j)) = " " Or (Cells(i + 3, 12 + j)) = " " Or
(Cells(i + 3, 12 + j)) = " " Or (Cells(i + 3, 12 + j)) = " " Then
' MsgBox "celda" & i & "," & j
Else
registro(i, 2 + j) = CDbl(Cells(i + 3, 12 + j))
' MsgBox registro(i, 2 + j)
End If
Next j
Next i
' sumamos datos
Dim smaterialMES(1 To 3000, 1 To 3000) As Single
For i = 1 To ndatos
sregistro(Int(registro(i, 1))) = registro(i, 2) + sregistro(registro(i, 1))
'SUMA MATERIALES
For j = 1 To nmateriales
smaterialMES(Int(registro(i, 1)), j) = registro(i, 2 + j) + smaterialMES(Int(registro(i,
1)), j)
Next j
Next i
' datos sumados, AHORA ordenamos
For i = 1 To ndatos
For j = 1 To ndatos - 1
If borrador(j) > borrador(j + 1) Then
'cambbio para que vaya de manmor a mayor
Dim cambiador As Single

cambiador = borrador(j)
borrador(j) = borrador(j + 1)
borrador(j + 1) = cambiador
Else
End If
Next j
Next i

' ahora debemos borrar los items dobles

For i = 1 To ndatos * 2

For j = 1 To ndatos - 1

If borrador(j) = borrador(j + 1) Then

' borramos la fila


For k = j To ndatos
borrador(k + 1) = borrador(k + 2)
Next k
Else

End If

Next j
Next i
' ahora buscamos el cero y averiguamos cuantos items hay
nitems = 0

For i = 1 To ndatos

If borrador(i) = 0 Then

' hasta qui sabemos cuantos items hay

GoTo 1
Else

nitems = nitems + 1

End If

Next i
1:

MsgBox nitems

'informes semanales
For l = 1 To 4
' sumamos datos
For i = diassemana(l) + 1 To diassemana(l + 1)
sregistroSEMANAS(Int(registro(i, 1)), l) = registro(i, 2) +
sregistroSEMANAS(Int(registro(i, 1)), l)
' determinamos rendmientos por semana
Select Case l
Case 1

For j = 1 To nmateriales

materiales01(Int(registro(i, 1)), j) = registro(i, 2 + j) + materiales01(Int(registro(i, 1)),


j)

Next j

Case 2
For j = 1 To nmateriales

materiales02(Int(registro(i, 1)), j) = registro(i, 2 + j) + materiales02(Int(registro(i, 1)),


j)

Next j

Case 3
For j = 1 To nmateriales

materiales03(Int(registro(i, 1)), j) = registro(i, 2 + j) + materiales03(Int(registro(i, 1)),


j)

Next j
Case 4

For j = 1 To nmateriales

materiales04(Int(registro(i, 1)), j) = registro(i, 2 + j) + materiales04(Int(registro(i, 1)),


j)

Next j
End Select

Next i

' ahora mostramos los items que se han sumado


Next l
' mostramos semana

For i = 1 To nitems
Cells(6 + ndatos + i, 4) = borrador(i)
For j = 1 To nmateriales
If smaterialMES(Int(borrador(i)), j) = 0 Then
Else
Cells(6 + ndatos + i, 12 + j) = smaterialMES(Int(borrador(i)), j)
End If
Next j

For j = 1 To ndatos
If borrador(i) = CDbl(Cells(j + 3, 4)) Then
Cells(6 + ndatos + i, 5) = Cells(j + 3, 5)
Cells(6 + ndatos + i, 6) = Cells(j + 3, 6)
GoTo NOMBRE
End If

Next j

NOMBRE:
Cells(6 + ndatos + i, 10) = sregistro(borrador(i))
Next i

' mostramos los valores semanales


'contador de items

Dim contador As Integer


contador = 0

For i = 1 To 2000

If sregistroSEMANAS(i, 1) <> 0 Or sregistroSEMANAS(i, 2) <> 0 Or sregistroSEMANAS(i,


3) <> 0 Or sregistroSEMANAS(i, 4) <> 0 Then
contador = contador + 1

'mostramos fila el item


Cells(500 + contador, 4) = i
Cells(500 + contador, 10) = sregistroSEMANAS(i, 1)
Cells(500 + contador, 11) = sregistroSEMANAS(i, 2)
Cells(500 + contador, 12) = sregistroSEMANAS(i, 3)
Cells(500 + contador, 13) = sregistroSEMANAS(i, 4)
End If
Next i

' ahora mostramos resultados del mes

' mostramos resndimientos ne la otra hoja

contador = 0

For i = 1 To 2000

If sregistroSEMANAS(i, 1) <> 0 Or sregistroSEMANAS(i, 2) <> 0 Or sregistroSEMANAS(i,


3) <> 0 Or sregistroSEMANAS(i, 4) <> 0 Then
contador = contador + 1
Dim filador As Integer

filador = 5 * (contador)
'mostramos fila el item
Cells(filador + 850, 4) = i

'MsgBox i
Cells(filador + 850, 10) = sregistroSEMANAS(i, 1)
Cells(filador + 850 + 1, 10) = sregistroSEMANAS(i, 2)
Cells(filador + 850 + 2, 10) = sregistroSEMANAS(i, 3)
Cells(filador + 850 + 3, 10) = sregistroSEMANAS(i, 4)

For j = 1 To nmateriales
If Val(sregistroSEMANAS(i, 1)) = 0 Then
Cells(filador + 850, 12 + j) = 0
Else
Cells(filador + 850, 12 + j) = materiales01(i, j) / sregistroSEMANAS(i, 1)
End If

If Val(sregistroSEMANAS(i, 2)) = 0 Then


Cells(filador + 1 + 850, 12 + j) = 0
Else
Cells(filador + 1 + 850, 12 + j) = materiales02(i, j) / sregistroSEMANAS(i, 2)
End If

If Val(sregistroSEMANAS(i, 3)) = 0 Then


Cells(filador + 2 + 850, 12 + j) = 0
Else
Cells(filador + 2 + 850, 12 + j) = materiales03(i, j) / sregistroSEMANAS(i, 3)
End If

If Val(sregistroSEMANAS(i, 4)) = 0 Then


Cells(filador + 3 + 850, 12 + j) = 0
Else
Cells(filador + 3 + 850, 12 + j) = materiales04(i, j) / sregistroSEMANAS(i, 4)
End If

Next j
End If
Next i

End Sub

You might also like