Hello all. Here is my data (there are four columns and ~5000 rows):
________________________________________________
Name.........Start Time.........End Time..........Duration
________________________________________________
..................8AM..................9AM..................1 hour
.................930 AM..............11AM..................1.5 hours
Lightbulb.....11AM..................12PM................1 hour
.................12PM....................1PM.................1 hour
..................1PM....................2PM..................1 hour
________________________________________________
..................8AM..................9AM..................1 hour
Fan.............9AM..................12PM.................3 hours
..................5PM..................530PM...............0.5 hours
_________________________________________________
etc. etc. etc.
The macro below (from this thread on page 2: http://www.mrexcel.com/forum/excel-questions/101119-sumif-merged-cells-2.html) is able to sum a variable number of the duration rows depending on when the "name" merged cell (i.e. "lightbulb") stops and ends:
The syntax for that question is as follows:
I cannot unmerge the "name" cell to make this easier unfortunately. As you can see, the number of rows each set of "names" contains varies - sometimes it is 5 rows, sometimes it is 3 rows, sometimes it isn't even a merged cell and is only 1 row.
What I would like to do now is the following: notice how the end time of a certain row can sometimes be identical to the start time of the following row. I would like to count the number of instances that there are identical end&start times for each set of "name" cells (which are often - but sometimes not - merged cells).In other words: determining how many occurrences of identical end&start times there are for "lightbulb" (which would be 3 in this example), for "fan" (which would be 1 in this example), etc.
Can you help me out? I have almost zero macro experience. The macro above is working perfectly for the summing task and and might make this counting task an easy question to answer?
Thanks!
________________________________________________
Name.........Start Time.........End Time..........Duration
________________________________________________
..................8AM..................9AM..................1 hour
.................930 AM..............11AM..................1.5 hours
Lightbulb.....11AM..................12PM................1 hour
.................12PM....................1PM.................1 hour
..................1PM....................2PM..................1 hour
________________________________________________
..................8AM..................9AM..................1 hour
Fan.............9AM..................12PM.................3 hours
..................5PM..................530PM...............0.5 hours
_________________________________________________
etc. etc. etc.
The macro below (from this thread on page 2: http://www.mrexcel.com/forum/excel-questions/101119-sumif-merged-cells-2.html) is able to sum a variable number of the duration rows depending on when the "name" merged cell (i.e. "lightbulb") stops and ends:
Code:
Public Function SUMMERGE(Target As Range, ColumnOffset As Integer, LookupVal As Variant) As DoubleDim MySum As Double, c As Range, cell As Range
On Error GoTo errhand
If Target.Columns.Count > 1 Then GoTo errhand
Set Target = Intersect(Target, ActiveSheet.UsedRange)
For Each c In Target
If IsError(c) Then GoTo nextcell
If c.Value = LookupVal Then
If c.MergeCells Then
If c.Address = c.MergeArea(1).Address Then
For Each cell In c.MergeArea
MySum = MySum + cell.Offset(0, ColumnOffset).Value
Next cell
End If
Else
MySum = MySum + c.Offset(0, ColumnOffset).Value
End If
End If
nextcell:
Next c
SUMMERGE = MySum
Exit Function
errhand:
SUMMERGE = CVErr(1)
End Function
The syntax for that question is as follows:
Syntax
=SUMMERGE(Target Range, Offset Column, Lookup Value)
Target range is the column of cells you wish to look within for the lookup value. This will be the column that has the merged cells. -----> "Name" column
Offset Column is a number representing the column to Sum. A positive number means that many columns to the right of the Target column, while a negative number represents that many columns to the left. ------> "3" in this case
Lookup Value is the value you are looking for. ------> i.e. "Lightbulb" or "Fan"
I cannot unmerge the "name" cell to make this easier unfortunately. As you can see, the number of rows each set of "names" contains varies - sometimes it is 5 rows, sometimes it is 3 rows, sometimes it isn't even a merged cell and is only 1 row.
What I would like to do now is the following: notice how the end time of a certain row can sometimes be identical to the start time of the following row. I would like to count the number of instances that there are identical end&start times for each set of "name" cells (which are often - but sometimes not - merged cells).In other words: determining how many occurrences of identical end&start times there are for "lightbulb" (which would be 3 in this example), for "fan" (which would be 1 in this example), etc.
Can you help me out? I have almost zero macro experience. The macro above is working perfectly for the summing task and and might make this counting task an easy question to answer?
Thanks!