+ Reply to Thread
Results 1 to 9 of 9

creating dates in the past with given date

  1. #1
    Registered User
    Join Date
    03-14-2008
    Posts
    9

    creating dates in the past with given date

    Hi, I have two cells with data like following:

    A B c
    06/11/2006 1 ??
    The cell B will have values like 1 (for Daily), 2 (for Weekly), and 3 (for Monthly).
    Depending upon the value of Cell B, I need to go -10 in the past and populate 10 cells with those dates. For example:

    A B c D ... L
    06/11/2006 1 06/10/2008 06/09/2008 ...06/02/2008

    Similarly if Cell B=2, I need to go -10 weeks and populate cells C to L with those dates and similarly for Cell B=3, -10 months.

    Any ideas how can this be done? If my question is not clear, please let me know immediately. thanks in advance.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    If your date is in A1 and the code is in B1, enter this in C1 and copy across to L1:

    =CHOOSE($B$1,$A$1-COLUMN(A$1),$A$1-7*COLUMN(A$1),DATE(YEAR($A$1),MONTH($A$1)-COLUMN(A$1),DAY($A$1)))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Assuming A2 has start date and B2, 1, 2 or 3 you could use this formula in C2 copied across to L2

    =IF($B2="","",CHOOSE($B2,$A2-COLUMNS($C2:C2),$A2-COLUMNS($C2:C2)*7,EDATE($A2,COLUMNS($C2:C2))))

    Note: EDATE requires Analysis ToolPak add-in.......

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by daddylonglegs
    Assuming A2 has start date and B2, 1, 2 or 3 you could use this formula in C2 copied across to L2

    =IF($B2="","",CHOOSE($B2,$A2-COLUMNS($C2:C2),$A2-COLUMNS($C2:C2)*7,EDATE($A2,COLUMNS($C2:C2))))

    Note: EDATE requires Analysis ToolPak add-in.......

    Hmmm... close! not bad, eh?!

  5. #5
    Registered User
    Join Date
    03-14-2008
    Posts
    9
    Hi guys, thanks for your replies. I applied NBVCs formula. It is showing 06/10/2008 in all 10 cells. I have date in cell A1 and values 1,2,3 in cell A2. My display cells are C11 to L11. May be I didn't copy it right. Please advise. Thanks.
    This is what I put in C11 to L11
    =CHOOSE($A$2,$A$1-COLUMN(A$1),$A$1-7*COLUMN(A$1),DATE(YEAR($A$1),MONTH($A$1)-COLUMN(A$1),DAY($A$1)))

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Check that you have calculations set to automatic...

    Go to Tools|Options and then Calculation tab... the Automatic radio button should be selected.

  7. #7
    Registered User
    Join Date
    03-14-2008
    Posts
    9
    Yes, that automatic option is selected.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    So you copied the formula only to C11, then you clicked on the little black square at the bottom right corner of C11, held the mouse button down and dragged the formula across to D11?

  9. #9
    Registered User
    Join Date
    03-14-2008
    Posts
    9
    ummm. i guess i did not do that. i just copied the exact same formula from the top bar and pasted it in each cell. let me try again with what you just mentioned.

+ 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