breaking up time between 2 dates - displaying data for each day

ZachD86

New Member
Joined
Mar 30, 2015
Messages
2
Hi,

I'm currently working on an excel spreadsheet that calculates emissions (volatile organic compounds, and hazardous air pollutants) for a client. On the "Data Entry" sheet users input in the following:

B4 - Start date (example - 1/1/15)
C4 - Start Time (example - 12:00PM)
D4 - End date (example - 1/2/15)
E4 - End Time (example - 12:00PM)
F4 - Product Name (example - DB305)
G4 - Batch amount - (example - 5000 lbs)
H7 - VOC Average (lookup using vlookup)
H8 - VOC total Batch Emissions (H7 * batch amount)
H9 - HAP Average (lookup using vlookup)
H10 - HAP total batch emissions (H9 * Batch amount)

From the user input data, I use Vlookups to calculate VOC and HAP emissions depending on the product and batch amount entered. I have a command button that takes the user input data and moves one sheet over and pastes the data in the "Batch Entries" worksheet.

"Batch Entries":
Column B = StartDate/Time (DataEntry B4+ DataEntry C4)
Column C = EndDate/Time (DataEntry D4 + DataEntry E4)
Column D = Product
Column E = Batch Amount
Column F = Total Batch Time (EndDate/Time - StartDate/Time)
Column G = VOC Emissions (calculated in data entry, Vlookup value X Batch amount)
Column H = HAP Emissions (calculated in data entry, Vlookup value X Batch amount)

From here I can calculate hourly, daily and monthly emissions.

The issue is, if the user inputs say Jan 1 12:00PM - Jan 3 12:00PM, it will print the following in "Batch Entries"
B4 - 1/1/15 12:00PM
C4 - 1/3/15 12:00PM
D4 - FX504 (Product name)
E4 - Batch Amount 8,317 (user entered batch amount)
F4 - 48.00 (total batch hours)
G4 - 0.533 lbs (calculated VOC amount)
H4 - 0.532 lbs (calculated HAPS amount)

The facility needs to know emissions on a daily timeline, so I need some sort of code to look at the data and break it up if the batch spans over several days:

Jan 1 12:00PM - Jan 1 11:59 PM FX504 8,317 12 hours voc amount HAP amount
Jan 2 12:00 AM - Jan 2 11:59 PM FX504 8,317 24 hours voc amount HAP amount
Jan 3 12:00 AM - Jan 3 12:00 PM FX504 8,317 12 hours voc amount HAP amount

The code to my command button on the user input sheet is as follows:

Private Sub CommandButton1_Click()
Dim StartDateTime As Single
Dim EndDateTime As Single
Dim Date1 As Single
Dim Product As String
Dim Batchlb As Single
Dim BatchTime As Single
Dim VOCTotal As Single
Dim HAPTotal As Single
Dim SumIfDate As Single
Worksheets("Data Entry").Select
StartDateTime = Range("B4") + Range("C4")
EndDateTime = Range("D4") + Range("E4")
Product = Range("F4")
Batchlb = Range("H4")
BatchTime = Range("I4")
VOCTotal = Range("H8")
HAPTotal = Range("H10")
Worksheets("Batch Entries").Select
Worksheets("Batch Entries").Range("B2").Select
If Worksheets("Batch Entries").Range("B2").Offset(1, 0) <> "" Then
Worksheets("Batch Entries").Range("B2").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = StartDateTime
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = EndDateTime
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Product
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Batchlb
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = BatchTime
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = VOCTotal
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = HAPTotal
Worksheets("Data Entry").Select
End Sub

Any help would be greatly appreciated as I am completely stuck!

Zach
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
test 101/01/201504/01/2015774.00
test 209/01/201515/01/2015667.00
01/01/201502/01/201503/01/201504/01/201505/01/201506/01/201507/01/201508/01/201509/01/201510/01/201511/01/201512/01/201513/01/201514/01/201515/01/201516/01/201517/01/201518/01/201519/01/201520/01/2015
test 177777777
test 266666666666666
formula for test 1 01/01/2015 (77)
=IF(AND(E$17>=$C2,E$17<=$D2),$E2,"")

<colgroup><col><col><col><col><col><col><col span="19"></colgroup><tbody>
</tbody>
 
Upvote 0
it is a formula that enters data into every date between 2 dates - it is for you to adapt to your own needs.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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