Forum Discussion

DianeDennis's avatar
DianeDennis
Brass Contributor
Jun 19, 2023
Solved

Can I auto-fill MM/DD based on date entered in a different field?

Hi!   I have a form that auto-fills the individual dates for a week based on the week-ending date entered by the user into cell M8.   M8 is formatted - Date 3/14/2012   The code (script?) I'm u...
  • SnowMan55's avatar
    SnowMan55
    Jun 20, 2023

    DianeDennis 

    Sure. I have put examples and explanatory text and Excel notes (in cells with a red marker in the upper right) into the attached workbook.

     

    Absolute addressing (using the $ in front of the column letter and/or row number) tells Excel that if this cell is copied, leave this portion of the address as-is.  Relative addressing (without the $) tells Excel that if this cell is copied, adjust the column letter and/or row number as seems to be appropriate; e.g., if the original formula referenced a cell two columns to that cell's left, Excel will change the pasted formula to refer to the cell two columns to this cell's left.

     

    I'm guessing that your data is structured something like the worksheets in the attached workbook. With the upper formula from my post (I'll refer to it as formula 1), copying cell N8 to other rows can produce undesirable results, depending on what is in column M. Formula 2, on the second worksheet, behaves better, as shown.

     

    Bonus format code: The code dddd displays the day of the week fully spelled out.

     

    Bonus formula: Your spreadsheet might have adjacent dates in adjacent columns, as shown on the Formula2 worksheet. Rather that subtracting a different number of days from the Week Ending date in each of those columns, I put a formula in cell O8 that examines what column it is stored in (the "COLUMN()" part) and what column the Week Ending date is stored in (the "COLUMN($M8)" part) to calculate the date. That way, O8 can be copied to the right (as I have done, and back into cell N8 if you wish) without change. It can also be copied to other rows.  If you don't understand that formula, feel free to ignore it.

     

    Edit: clarified absolute addressing

Resources