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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

t4373125

Board Regular
Joined
Jun 26, 2002
Messages
52
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,010
Messages
5,834,880
Members
430,325
Latest member
Thony

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
Top