I am attempting to create a do while loop to loop through the following date ranges and several into the future.
06/23/2011 to 07/7/2011
07/7/2011 to 07/21/2011
07/21/2011 to 08/4/2011
08/4/2011 to 08/18/2011
The following code runs when a command button on a sheet is clicked.
PayDue Function
The code above works correctly for the first interval, however each interval after that starts with 06/23/2011. instead of jumping to the next date interval.
So what is happening is this:
06/23/2011 to 07/7/2011
06/23/2011 to 07/21/2011
06/23/2011 to 08/4/2011
06/23/2011 to 08/18/2011
Ultimately what needs to happen is each interval needs to have a code associated with it and will input two columns to the left.
Column C = 7/1/2011
Column A = 1Due
Or
Column C = 7/8/2011
Column A = 2Due
For example:
06/23/2011 to 07/7/2011 = 1Due
07/7/2011 to 07/21/2011 = 2Due
07/21/2011 to 08/4/2011 = 3Due
08/4/2011 to 08/18/2011 = 4Due
Note: When 7/7/2011 occurs, the code would reset and 7/7/2011 would be equal to 1Due.
So the following code will need to update with each loop to show a different code (1Due, 2Due, 3Due). Also the code needs to be changed to update the date interval.
So what I need assistance with is changing the code above to work for multiple intervals, as the issue is with using only PayDue for the first half of the If statement. I cannot think of a way to use the initial interval of PayDue and PayDue + intCounter, then reuse Paydue + intCounter as PayDue and have the loop update the interval. Also with the update, the 1Due, would become a 2Due and so on.
For example, the current PayDue and PayDue + intCounter only updates the second half of the interval.
06/23/2011 to 07/7/2011
06/23/2011 to 07/21/2011
06/23/2011 to 08/4/2011
06/23/2011 to 08/18/2011
and the code remains 1Due because the date interval is not updating.
Any help would be great.
06/23/2011 to 07/7/2011
07/7/2011 to 07/21/2011
07/21/2011 to 08/4/2011
08/4/2011 to 08/18/2011
The following code runs when a command button on a sheet is clicked.
Code:
Private Sub CommandButton1_Click()
Dim intCounterDate As Integer
Dim intCounterCode As Integer
Dim intTest As Integer
intTest = 1
intCounterDate = 1
intCounterDate = 14
Do While intTest = 1
MsgBox PayDue & " | " & PayDue + intCounterDate
If intCounterDate >= 364 Then
intTest = 0
End If
intCounterDate = intCounterDate + 14
If (IsDate(ActiveCell)) Then
ActiveCell.Font.Color = RGB(0, 0, 0)
ActiveCell.NumberFormat = "mm/d/yyyy"
If (ActiveCell >= PayDue And ActiveCell < PayDue + intCounterDate) Then
ActiveCell.Offset(0, -2).Value = intCounterCode & "Due"
ActiveCell.Offset(0, -2).NumberFormat = "@"
ActiveCell.Offset(0, -2).Font.Color = RGB(0, 0, 0)
intCounterCode = intCounterCode + 1
End If
End If
Loop
End Sub
PayDue Function
Code:
Function PayDue()
FirstPayDate = DateValue("7 Jan 2010") 'hard coded value
'FirstPayDate = ThisWorkbook.Sheets("Sheet2").Range("B2").value 'the same from a sheet
PayDue = FirstPayDate + Int((Date - FirstPayDate) / 14) * 14
End Function
The code above works correctly for the first interval, however each interval after that starts with 06/23/2011. instead of jumping to the next date interval.
So what is happening is this:
06/23/2011 to 07/7/2011
06/23/2011 to 07/21/2011
06/23/2011 to 08/4/2011
06/23/2011 to 08/18/2011
Ultimately what needs to happen is each interval needs to have a code associated with it and will input two columns to the left.
Column C = 7/1/2011
Column A = 1Due
Or
Column C = 7/8/2011
Column A = 2Due
For example:
06/23/2011 to 07/7/2011 = 1Due
07/7/2011 to 07/21/2011 = 2Due
07/21/2011 to 08/4/2011 = 3Due
08/4/2011 to 08/18/2011 = 4Due
Note: When 7/7/2011 occurs, the code would reset and 7/7/2011 would be equal to 1Due.
So the following code will need to update with each loop to show a different code (1Due, 2Due, 3Due). Also the code needs to be changed to update the date interval.
Code:
If (ActiveCell >= PayDue And ActiveCell < PayDue + intCounterDate) Then
ActiveCell.Offset(0, -2).Value = intCounterCode & "Due"
ActiveCell.Offset(0, -2).NumberFormat = "@"
ActiveCell.Offset(0, -2).Font.Color = RGB(0, 0, 0)
intCounterCode = intCounterCode + 1
End If
So what I need assistance with is changing the code above to work for multiple intervals, as the issue is with using only PayDue for the first half of the If statement. I cannot think of a way to use the initial interval of PayDue and PayDue + intCounter, then reuse Paydue + intCounter as PayDue and have the loop update the interval. Also with the update, the 1Due, would become a 2Due and so on.
For example, the current PayDue and PayDue + intCounter only updates the second half of the interval.
06/23/2011 to 07/7/2011
06/23/2011 to 07/21/2011
06/23/2011 to 08/4/2011
06/23/2011 to 08/18/2011
and the code remains 1Due because the date interval is not updating.
Any help would be great.