Private Sub Worksheet_Change(ByVal Target As Range)
colno = Target.Column
rowno = Target.Row
If rowno < 8 Then Exit Sub ' exit is not changing an entry
If colno = 6 Or colno = 7 Or colno = 8 Or colno = 12 Then
inarr = Range(Cells(rowno, 6), Cells(rowno, 12)) ' pict up inputs from the line that has changed
Application.EnableEvents = False
With Worksheets("Sheet2")
' **************************************************
If inarr(1, 1) = "Recurring" Then
.Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57)) = "" ' Clear entire row of week entries
outarr = .Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57))
amnt = inarr(1, 7) ' amount
swk = inarr(1, 2) ' spend week
If swk < 1 Or swk = "" Then
MsgBox (" You must enter a value for Spend week")
GoTo enableexit
End If
frq = inarr(1, 3)
If frq < 1 Or frq = "" Then
MsgBox (" You must enter a value for Frequency")
GoTo enableexit
End If
For i = swk To swk + frq - 1
outarr(1, i) = amnt / frq ' write out weekly stuff in a loop ***
Next i
.Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57)) = outarr
.Range(.Cells(rowno - 3, 3), .Cells(rowno - 3, 3)) = "Recurring"
End If
'***************************************************************
If inarr(1, 1) = "Single" Then
.Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57)) = "" ' Clear entire row of week entries
outarr = .Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57))
amnt = inarr(1, 7) ' amount
swk = inarr(1, 2) ' spend week
If swk < 1 Or swk = "" Then
MsgBox (" You must enter a value for Spend week")
GoTo enableexit
End If
outarr(1, swk) = amnt ' write out weekly stuff in a loop
.Range(.Cells(rowno - 3, 3), .Cells(rowno - 3, 3)) = "Single"
.Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57)) = outarr
Range("H" & Target.Row).ClearContents ' Clear frq cell if "Single" selected ***
End If
'******************************************************
If inarr(1, 1) = "Manual" Then
rspn = MsgBox("Clear any data in Sheet 2 row? ", vbYesNo) ' Popup warning of clearing data ***
If rspn = vbNo Then GoTo enableexit '***
.Range(.Cells(rowno - 3, 6), .Cells(rowno - 3, 57)) = "" ' Clear entire row of week entries
.Range(.Cells(rowno - 3, 3), .Cells(rowno - 3, 3)) = "Manual"
Range("G" & Target.Row).ClearContents '[/COLOR] ***
Range("H" & Target.Row).ClearContents ' Clear frq and swk cells if "Manual" selected ***
Sheets("Sheet2").Activate ' Activate Sheet 2 ***
ActiveSheet.Range("F" & Target.Row - 3).Select ' Select first week of active row ***
End If
End With
End If
enableexit:
Application.EnableEvents = True
End Sub