SUMA CONDICIONAL 2 CONDICIONES

Renzo G

New Member
Joined
May 6, 2002
Messages
19
JP,

Tengo una tabla de 2 columnas, en la primera estan las horas (formato horas) en la segunda columna el numero de elementos que llegaron a esa hora.
Lo que quiero es hacer una tabla de resumen tipo histograma que sume los elementos en intervalos de 30 minutos.
Gracias de antemano,

Renzo
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hola.

Prueba esta macro y dime si hay algo que no entiendas. Puedes modificar los valores iniciales para que se adapte a tus necesidades.

Sub ResumenHoras()

Dim Hora As Date
Dim i As Integer

i = 2
'especificar la primera hora del resumen
Hora = #8:00:00 AM#
Range("E" & i).Value = Hora

'comenzar a analizar los datos
Range("A2").Select

'mientras queden datos
While ActiveCell.Value <> ""
'caso que no se tenga que cambiar la hora
If ActiveCell.Value < Hora + #12:30:00 AM# Then
'sumar la cantidad
Range("F" & i).Value = Range("F" & i).Value + ActiveCell.Offset(0, 1).Value
'caso que se tenga que cambiar de hora
Else
'nueva hora
i = i + 1
Hora = Hora + #12:30:00 AM#
Range("E" & i).Value = Hora
While ActiveCell.Value >= Hora + #12:30:00 AM#
'nueva hora
i = i + 1
Hora = Hora + #12:30:00 AM#
Range("E" & i).Value = Hora
Wend
'sumar la cantidad
Range("F" & i).Value = Range("F" & i).Value + ActiveCell.Offset(0, 1).Value
End If
'ir al siguiente valor
ActiveCell.Offset(1, 0).Select
Wend

End Sub


Un saludo.
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,661
Members
450,706
Latest member
LGVBPP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top