View Single Post
 
Old 04-17-2014, 04:06 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try adding the following macro to your 'Inputs' worksheet's code module:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim StartDate As Date, Duration As Long, i As Long
With ActiveSheet
  If Intersect(Target, .Range("D9:D11")) Is Nothing Then Exit Sub
  If ActiveSheet.Range("D9") = "" Then Exit Sub
  If ActiveSheet.Range("D10") < 1 Then Exit Sub
  StartDate = .Range("D9").Value
  Duration = .Range("D11").Value
End With
With Worksheets("O&M")
  .Range("A5:D" & .UsedRange.Rows.Count).ClearContents
  .Range("A5").Value = StartDate
  .Range("B5").Value = DateAdd("yyyy", 1, StartDate) - 1
  .Range("C" & i + 5).Value = Format(StartDate, "yyyy")
  .Range("D" & i + 5).Value = 1
  For i = 1 To Duration - 1
    .Range("A" & i + 5).Value = DateAdd("yyyy", i, StartDate)
    .Range("B" & i + 5).Value = DateAdd("yyyy", i + 1, StartDate) - 1
    .Range("C" & i + 5).Value = Format(DateAdd("yyyy", i, StartDate), "yyyy")
    .Range("D" & i + 5).Value = i + 1
  Next
End With
End Sub
The macro will run automatically any time you select a cell in the D9-D11 range.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 04-17-2014 at 04:11 PM. Reason: Code revision
Reply With Quote