+ Reply to Thread
Results 1 to 5 of 5

Auto date fill

  1. #1
    Registered User
    Join Date
    08-27-2009
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    2

    Auto date fill

    Hello,

    Using excel.

    I'm looking to compose a macro to automatically fill a date range for example
    if c1 = 10/10/09 then d1 = one week after "17/10/09" e1 = 2 weeks after "24/10/09" and so on until 4 weeks time.
    also if b1 = w then above script kicks in but if b1 = m then script will not run.

    One other thing, this is for the whole spreadsheet, the exact ref range will be

    if d10= w then autofil with date range e10 f10 g10 h10
    if d11= w then autofil with date range e11 f11 g11 h11
    and so on...

    Any help would be much apprieciated

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Auto date fill

    See if the attached is what you intended. There is a conflict in the columns you referenced in your example so I have assumed Column-D holds "m" or "w" and Column-E holds the intial date entry.

    In the worksheet_Change event;
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Auto date fill

    You can accomplish the same thing with no macro, just worksheet formulas, if you're interested.

    In E10:
    =IF(AND($B10="w", $D10="w", $C10>0), $C10+7, "")

    In F10:
    =IF($E10="", "", E10+7
    Copy that cell across into G10 and H10.

    Then copy those four cells down as far as you want.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    08-27-2009
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Auto date fill

    This hasn't quite worked, if i include an attachment of my work sheet it my help you to see what i need.

    thank you.
    Attached Files Attached Files

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Auto date fill

    Code amended. Got the columns wrong as I was a bit confused by your initial post. Should work now, but you'll need to copy the code to each sheet module.

    Please Login or Register  to view this content.
    I agree with JBeaucaire on the use of formulas, as they are always faster and more efficient than VBA code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1