Hi all,
Apologies for the layout as code tags are not working.
I am populating sheets from a userform with work dates for different tasks for different employees and are trying to sum the data for display in the user form, days worked for year etc. No problem with this, just gotta get the data to output. I have 5 different columns where the results of the equation will be.
I am attempting in Row C to subtract Row A from Row B in a dynamic range, below is some code I have modified to attempt this. How can I change the
Sub Sum_Dates()
Dim LastRow As Long
Dim i As Long
Dim iCol As Integer
LastRow = 0
' Sum_Dates Macro
For iCol = 1 To 4 'Columns C:D
iRow = Cells(65536, iCol).End(xlUp).Select
If iRow > LastRow Then LastRow = iRow
Next iCol
With Application.WorksheetFunction
'Place row totals in column C
ActiveCell.Offset(, -1).Select
For i = 1 To LastRow
If ActiveCell.Offset(, -1).Value <> " " And ActiveCell.Offset(, 1).Value = "2011" Then GoTo Line20
ActiveCell.FormulaR1C1 = "=SUM(RC[-1]-RC[-2]+1)"
Next i
Line20:
End With
End Sub
If some one could give me a guide to get the equation working in column C would be much appreciated.
Regards, Dave
Using Excel 2010 Windows 7[/SIZE]
Apologies for the layout as code tags are not working.
I am populating sheets from a userform with work dates for different tasks for different employees and are trying to sum the data for display in the user form, days worked for year etc. No problem with this, just gotta get the data to output. I have 5 different columns where the results of the equation will be.
I am attempting in Row C to subtract Row A from Row B in a dynamic range, below is some code I have modified to attempt this. How can I change the
so that it does not jump fromLastRow = 0
to theFor i = 1 To LastRow
As it is it only looks at one row then skips. The equation is meant to look at Col B and if there is a date in there and the year is, in this case 2011, it will continue the equation on all that meet the IF statement.End With
Sub Sum_Dates()
Dim LastRow As Long
Dim i As Long
Dim iCol As Integer
LastRow = 0
' Sum_Dates Macro
For iCol = 1 To 4 'Columns C:D
iRow = Cells(65536, iCol).End(xlUp).Select
If iRow > LastRow Then LastRow = iRow
Next iCol
With Application.WorksheetFunction
'Place row totals in column C
ActiveCell.Offset(, -1).Select
For i = 1 To LastRow
If ActiveCell.Offset(, -1).Value <> " " And ActiveCell.Offset(, 1).Value = "2011" Then GoTo Line20
ActiveCell.FormulaR1C1 = "=SUM(RC[-1]-RC[-2]+1)"
Next i
Line20:
End With
End Sub
If some one could give me a guide to get the equation working in column C would be much appreciated.
Regards, Dave
Using Excel 2010 Windows 7[/SIZE]