Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 04-17-2014, 04:06 PM
macropod's Avatar
macropod macropod is offline Excel to auto populate dates based on start and end Windows 7 32bit Excel to auto populate dates based on start and end Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to auto populate dates based on start and end Auto Populate Word From to Excel File webber Word 1 10-02-2013 02:52 PM
Start / End Dates in conjunction with man days loobs40 Project 5 09-19-2013 09:21 AM
how to populate textbox based on combobox selection in word IvanGeorgiev Word 1 02-21-2013 07:32 PM
Excel to auto populate dates based on start and end how to populate textbox based on combobox selection in word IvanGeorgiev Word VBA 1 02-21-2013 07:28 PM
Excel to auto populate dates based on start and end Task Start and End Dates OTPM Project 2 12-04-2011 09:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft