Sum between two dates only in calendar year and sum total (five) column pairs

fonk

New Member
Joined
Mar 30, 2009
Messages
49
Hi,
I have a user form with 2 tabs to input date data (not too many problems there) and also retrieve the sum of days for different tasks(problems there). I have five headings in row one, Columns A:B "Offshore", E:F "Travelling To Work", I:J "Travelling From Work", M:N "Workshop" & Q:S "Courses".
In row two I have date sets; "Start Date" and "End Date" under each heading. The next colum after each date set is free for totals.
Travel To (Start Date) is the only column that will have data in every row and I have referenced the other columns to this on the input side of the userform, therefore if someone goes Offshore the Offshore dates will align with the Travel To dates. That employee may next go to the workshop and that will leave a blank row between the last and next Offshore dates.
What I am attempting unsucessfully to do is check that the row date pairs ("Travel To" and "Travel From"), or part thereof, are in the current calendar year, sum these to the total column then sum the total of the column, I will then display then in a list box. This will to be done for each pair of columns so when a user selects the employee they will be able to see for the calendar year the days offshore, travel days, workshop days and course days. Another thing is that there could be a "Travel To" date but not a "Travel From" date as the employee could still be on the job.
Below is some downloaded code (thanks) that I have been attempting to massage into a usable form without success, to be honest I am unsure if I'm barking up the wrong tree with this code and at the moment can't step through it for errors, all my own. I have searched the forum but can't nut this one out without a bit of advice and guidance.
Cheers Dave
Excel 2010 on Windows 7

Code:
Private Sub daysCount()
Dim rngDates As Range
Dim dtEndDate As Date
Dim stStartDate As Date
Dim rngCell As Range
Dim sngResult As Single
Dim FinalRow As Long, i As Integer
FinalRow = Range("E65536").End(xlUp).Row
'set the range containing dates
Set rngDates = Range(Array("A4:FinalRow"))
 
'set start date
stStartDate = DateSerial(Year(Now), 1, 1)
'set end date
dtEndDate = DateSerial(Year(Now), 12, 31)
'loop through each cell in the range
For Each rngCell In rngDates
If rngCell.Offset(, 1).IsEmpty.Ignore Then GoTo Line44
Next
If rngCell.Value >= stStartDate & rngCell.Value <= dtEndDate Then
Cell.Offset(, 1).AsRange
 
End If
Line44:
 
End Sub
[\Code]
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi all,
Just a quick addition, the dates are entered via spin buttons on the user form then formatted on the worksheet as dd-mmm-yy.

Cheers, Dave
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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