OK...i'm revisiting with this problem....
the below code sorts through a number of rows and when it finds a change in column a it inserts a row. Also, when it finds the end of a working week it inserts another row.
Now the problem is, there is a fixed startdate and the working week is based on increments of 7, but if the first date for each section (the sections are divided based on a change in column a, where the other row is inserted) is greater by seven days than the start date it inserts a line. This is a problem as it isn't always the end of a working week, which is wehre i want the rows entered.
Hope I've explained that little issue well enough....any suggestions and/or subsequent solutions will be met with great gushing praise...
Han...
Sub weeklyTotal()
Const StartDate As Date = #6/29/2002#
Dim TestDate As Date
Dim RowNo As Long
Dim c As Range
TestDate = StartDate
RowNo = Range("A11").Row
Set c = Cells(RowNo, 1)
Do
' If next cell in Column A is blank all done
If IsEmpty(c.Offset(1, 0)) Then
c.Offset(1, 0).EntireRow.Select
Selection.Interior.ColorIndex = 3
Exit Do
End If
' Test for change in code in column A
If c.Value <> c.Offset(1, 0).Value Then
c.Offset(1, 0).EntireRow.Insert shift:=xlUp
c.Offset(1, 0).EntireRow.Select
Selection.Interior.ColorIndex = 3
TestDate = StartDate
RowNo = RowNo + 1
' Test for new week
ElseIf c.Offset(1, 3).Value - TestDate > 7 Then
TestDate = TestDate + (Int((c.Offset(1, 3).Value - TestDate) / 7) * 7)
c.Offset(1, 0).EntireRow.Insert shift:=xlUp
c.Offset(1, 0).EntireRow.Select
Selection.Interior.ColorIndex = 3
RowNo = RowNo + 1
End If
RowNo = RowNo + 1
Set c = Cells(RowNo, 1)
Loop
End Sub
the below code sorts through a number of rows and when it finds a change in column a it inserts a row. Also, when it finds the end of a working week it inserts another row.
Now the problem is, there is a fixed startdate and the working week is based on increments of 7, but if the first date for each section (the sections are divided based on a change in column a, where the other row is inserted) is greater by seven days than the start date it inserts a line. This is a problem as it isn't always the end of a working week, which is wehre i want the rows entered.
Hope I've explained that little issue well enough....any suggestions and/or subsequent solutions will be met with great gushing praise...
Han...
Sub weeklyTotal()
Const StartDate As Date = #6/29/2002#
Dim TestDate As Date
Dim RowNo As Long
Dim c As Range
TestDate = StartDate
RowNo = Range("A11").Row
Set c = Cells(RowNo, 1)
Do
' If next cell in Column A is blank all done
If IsEmpty(c.Offset(1, 0)) Then
c.Offset(1, 0).EntireRow.Select
Selection.Interior.ColorIndex = 3
Exit Do
End If
' Test for change in code in column A
If c.Value <> c.Offset(1, 0).Value Then
c.Offset(1, 0).EntireRow.Insert shift:=xlUp
c.Offset(1, 0).EntireRow.Select
Selection.Interior.ColorIndex = 3
TestDate = StartDate
RowNo = RowNo + 1
' Test for new week
ElseIf c.Offset(1, 3).Value - TestDate > 7 Then
TestDate = TestDate + (Int((c.Offset(1, 3).Value - TestDate) / 7) * 7)
c.Offset(1, 0).EntireRow.Insert shift:=xlUp
c.Offset(1, 0).EntireRow.Select
Selection.Interior.ColorIndex = 3
RowNo = RowNo + 1
End If
RowNo = RowNo + 1
Set c = Cells(RowNo, 1)
Loop
End Sub