C
courtnml
Ok,
I have a macro that adds column A and B for sequential time intervals
(Its confusing see the example)
IE:
Before the Macro is Ran;
column A column B
05:00 1
05:00 1
05:00 0
After the Macro is Ranl
column A column B
05:00 2
Therefore it takes the numbers in column B and adds them to the time
interval and creates a SUM...the problem with the macro is when it
gets to the last set of intervals it deletes it and finshes without
errors, therefore if I was to go all the way through the intervals of
00:00-24:00 I would end up losing the 24:00 interval PLEASE HELP!!! e-
mail me at (e-mail address removed) if you want
Sub AnsweredMath()
Dim TimeInv
Dim cnt As Long
Dim total As Long
'sort the data
Range("A1").Activate
ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Order1:=xlAscending,
Header:=xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers
'Start at the second row - assumes will always be the first time
interval
Range("A1").Activate
TimeInv = ActiveCell.Value 'get the first range in the sheet;
assumes info starts at A1
While ActiveCell <> "" 'while the current cell is not blank -
processes until it hits a blank cell
If ActiveCell.Value <> TimeInv Then
ActiveCell.EntireRow.Insert 'insert a row and write out
values
ActiveCell.Value = TimeInv
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset.Value = total
total = 0 'reset total
cnt = 0 'reset cnt
ActiveCell.Offset(1, -1).Select 'go to the next row
TimeInv = ActiveCell.Value
Else
'capture count in varibles, then delete the row
cnt = ActiveCell.Offset(0, 1).Value
total = cnt + total
ActiveCell.EntireRow.Delete
End If
Wend
End Sub
I have a macro that adds column A and B for sequential time intervals
(Its confusing see the example)
IE:
Before the Macro is Ran;
column A column B
05:00 1
05:00 1
05:00 0
After the Macro is Ranl
column A column B
05:00 2
Therefore it takes the numbers in column B and adds them to the time
interval and creates a SUM...the problem with the macro is when it
gets to the last set of intervals it deletes it and finshes without
errors, therefore if I was to go all the way through the intervals of
00:00-24:00 I would end up losing the 24:00 interval PLEASE HELP!!! e-
mail me at (e-mail address removed) if you want
Sub AnsweredMath()
Dim TimeInv
Dim cnt As Long
Dim total As Long
'sort the data
Range("A1").Activate
ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Order1:=xlAscending,
Header:=xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers
'Start at the second row - assumes will always be the first time
interval
Range("A1").Activate
TimeInv = ActiveCell.Value 'get the first range in the sheet;
assumes info starts at A1
While ActiveCell <> "" 'while the current cell is not blank -
processes until it hits a blank cell
If ActiveCell.Value <> TimeInv Then
ActiveCell.EntireRow.Insert 'insert a row and write out
values
ActiveCell.Value = TimeInv
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset.Value = total
total = 0 'reset total
cnt = 0 'reset cnt
ActiveCell.Offset(1, -1).Select 'go to the next row
TimeInv = ActiveCell.Value
Else
'capture count in varibles, then delete the row
cnt = ActiveCell.Offset(0, 1).Value
total = cnt + total
ActiveCell.EntireRow.Delete
End If
Wend
End Sub