Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Range("A3:B57")) Is Nothing Then
ElseIf Not Intersect(Target, Range("M4:M7")) Is Nothing Then 'update shapes if user changed project dates
Call ResetShapes
'elseif Not intersect(Target, Range() is nothing then 'add other ranges to capture user changes
End If
End If
End Sub
Private Sub ResetShapes()
Dim PeriodWidth As Single, PeriodLeft As Single, PeriodDays As Long, ProjectTotalDays As Long
Dim StartDisplayPeriodDate As Date, EndDisplayPeriodDate As Date
Dim shp As Object, PointsPerDay As Single, i As Long, j As Long
StartDisplayPeriodDate = Cells(10, 11).Value
PeriodLeft = Cells(10, 11).Left ' absolute left position of period
EndDisplayPeriodDate = LastPeriodDate
PeriodWidth = CalcPeriodSize ' full width of columns for start-end period
PeriodDays = LastPeriodDate - StartDisplayPeriodDate + 1 ' inclusive number of days in PeriodWidth
PointsPerDay = PeriodWidth / PeriodDays ' how many screen points per day
ProjectTotalDays = Cells(7, 13) - Cells(4, 13) + 1 ' inclusive days
For Each shp In CrntShapes
Select Case Left(shp.Name, 6)
Case "Rectan"
shp.Left = PeriodLeft + (Cells(4, 13) - StartDisplayPeriodDate) * PointsPerDay 'PeriodLeft + (startday - periodstart)*PPD
shp.Width = ProjectTotalDays * PointsPerDay
Case "Diamon"
'figure which row to get symbol date
i = CLng(Right(shp.Name, 2)) - 1
j = i * 5
shp.Left = PeriodLeft + (Cells(13 + j, 6) - StartDisplayPeriodDate + 1) * PointsPerDay 'PeriodLeft + (startday - periodstart)*PPD
Case "Isosce"
'figure which row to get symbol date
i = CLng(Right(shp.Name, 2)) - 1
j = i * 5
shp.Left = PeriodLeft + (Cells(13 + j, 7) - StartDisplayPeriodDate + 1) * PointsPerDay 'PeriodLeft + (startday - periodstart)*PPD
End Select
Next shp
End Sub
Private Function CalcPeriodSize() As Single
Dim i As Long
i = 11 ' start column is K
Do Until Cells(10, i).Value = "" Or Cells(10, i).Value = 0 'look for first 0 or blank cell in period row 10
i = i + 1
Loop
CalcPeriodSize = (Cells(10, i - 1).Left + Cells(10, i - 1).Width) - Cells(10, 11).Left
End Function
Private Function LastPeriodDate() As Date
Dim i As Long
i = 11 ' start column is K
Do Until Cells(10, i).Value = "" Or Cells(10, i).Value = 0
i = i + 1
Loop
Select Case Cells(3, 6).Value
Case 1
LastPeriodDate = DateSerial(Year(Cells(10, i - 1).Value), Month(Cells(10, i - 1).Value) + 1, 0)
Case 2
LastPeriodDate = DateSerial(Year(Cells(10, i - 1).Value), Month(Cells(10, i - 1).Value) + 3, 0)
Case 3
LastPeriodDate = DateSerial(Year(Cells(10, i - 1).Value), Month(Cells(10, i - 1).Value) + 6, 0)
Case 4
LastPeriodDate = DateSerial(Year(Cells(10, i - 1).Value) + 1, Month(Cells(10, i - 1).Value) + 1, 0)
Case 5
LastPeriodDate = DateSerial(Year(Cells(10, i - 1).Value), Month(Cells(10, i - 1).Value), Day(Cells(10, i - 1).Value))
End Select 'Mode
End Function