Is this even possible? VBA question about adding rows for blank data...

nkemp15

New Member
Joined
Jan 31, 2014
Messages
36
I have a report that I run that will pull data for how many calls a team received for every 15 minute interval of the day. The issue I'm having with this report, is if there were no calls received, no data is put on the report. For example, it will give information for 1:00 1:15 1:30 2:00 & 2:15. In my example, no calls were received between 1:45 and 2:00, so 1:45 is completely missing from the report.

Is it possible to write a VBA script that will look through the times, and add in the missing rows with the blank times? I don't need any other data (since it would all be zeros anyways) I just need the rows to be added so management can visualize the times with zero calls.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Yes, I would think that it's not very hard to do that, but I don't think you necessarily need to have a Macro add in times if you want it all sorted into a new tab or workbook anyway. You might just want to create a template that includes all of those times you want to look at and build the Macro on top of that.
 
Upvote 0
Do you mean something like this(data structure) or how is your data structured


Excel 2010
ABCDE
2TimeCallsTimeCalls
301:00501:005
401:15601:156
501:30701:307
602:00401:450
702:004
Sheet1


That's like the before and after, is that right?
 
Upvote 0
This is how i think, PLEASE TRY ON A COPY OF The WORKSHEET

Code:
Sub addtimes()
    Dim i As Integer, j As Integer
    For i = Range("A" & Rows.Count).End(xlUp).Row To 3 Step -1
        a = 1 * Format(96 * (Range("A" & i) - Range("A" & i - 1)), "#")
        If a <> 1 Then
            For j = 1 To a - 1
                Rows(i).Resize(1).Insert
                Range("A" & i).Value = Range("A" & i + 1).Value - 1 / 96
                Range("B" & i).Value = 0
            Next j
        End If
    Next i
    
End Sub

The "96" is because 15mins is 1/96th of a day(15/60/24). If we were using 30mins, everywhere you have 96 would be 48 and son on
 
Last edited:
Upvote 0
That doesn't work at all. I get an error that says "Type Mismatch"

I don't know if this matters but there are dates in there as well.
 
Upvote 0
Dates in where? What column is your data in? Please post a sample of your spreadsheet.

I wrote the cide based on perceived idea of your data and it works flawlessly for me
 
Upvote 0
Capture.PNG

It's per 30 minutes and not per half hour also. I am new to this report and gave wrong information. I apologize.
 
Upvote 0
Looking at row 31 and 32, one is 6:30Pm the previous dAy while the other is 9AM the next day, how does the program know whether or not to add new rows between these times 'cos i presume 6:30Pm was the last call for that day....or do you only insert new rows when the day hasn't changed?
 
Upvote 0
We usually run the report on a monthly basis. We would need to know the times from 6:00 till 24:00 every day.
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,462
Members
448,965
Latest member
grijken

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