+ Reply to Thread
Results 1 to 11 of 11

Formula for adding different length columns

  1. #1
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,025

    Formula for adding different length columns

    Good Morning, I'm trying to come up with a formula to look at for example different year by weeks, for example how many units were sold in the first week of 2018 as against 2017.

    Column A (Number of weeks) Column B Sales for each week in 2018, Column C sales for each week in 2017 (and so on).

    Now I can obviously have row after row with number of weeks but is there a way that whatever number I place in column A, cell A1, it will read down that many rows in column B, C (and so on)

    Thanks for any help
    Last edited by Marvo; 10-07-2018 at 04:45 AM.

  2. #2
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,025

    Re: Formula for adding different length columns

    To try and elaborate, at present in Column A I have number "2".
    In Column B I have the formula =SUM(ALL!H3165:H3166)
    Is there a way that if I put "3" in Column A it will change the formula automatically to look for=SUM(ALL!H3165:H3167)
    I'm thinking the formula in column B would be the one to change?

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Formula for adding different length columns

    Will you please attach a SMALL sample Excel workbook (10-20 rows of data is usually enough)? Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution is also shown (mock up the results manually).

    3. Make sure that all confidential information is removed first!!

    4. Try to avoid using merged cells. They cause lots of problems!

    Unfortunately the attachment icon doesn't work at the moment. So, to attach an Excel file you have to do the following: Just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  4. #4
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,025

    Re: Formula for adding different length columns

    Thanks Glenn.

    Completely simplified. You have a column (B) with 20 rows with data. To add them all is simple =sum(B1:B20) So in column A if I input 20 the result in column B would be correct.
    What I am trying to do is input any number between 1-20 in Column A to give me a correct result. Example) 5 in Column A would be =sum(B1:B5)
    So I guess the solution is =sum(B1... and then plus how many rows the number in A1 is showing? That's where I come unstuck.

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Formula for adding different length columns

    Easier to follow!!

    =SUM(B1:INDEX($B$1:$B$20,A1))
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Formula for adding different length columns

    try this once
    =SUM(OFFSET(B1,,,A1))

  7. #7
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,025

    Re: Formula for adding different length columns

    That looks like its going to work Glenn but I have different rows and columns (G=A and H=B) and when I try to input your formula with either

    =SUM(H1:INDEX($H$3165:$H$3227,G2))
    or
    =SUM(H3165:INDEX($H$3165:$H$3227,G2))

    Its giving me an error in value?

  8. #8
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,025

    Re: Formula for adding different length columns

    Ghozi, That works, I've no idea how but it does. Thank you both so very much, I was aghast at having to change the formulas in dozens of cells each week.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Formula for adding different length columns

    No it doesn't, but it does need an addition, to take account of the case where G2 is blank


    =IF(G2="","",SUM(H3165:INDEX($H$3165:$H$3227,G2)))
    Attached Files Attached Files

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Formula for adding different length columns

    Beware of OFFSET. It recalculates EVERY TIME any change is made in your workbook. This can cause performance issues.

  11. #11
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,025

    Re: Formula for adding different length columns

    Okay. Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cell length formula to remove any characters over 31 in length
    By tehkayd in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-02-2015, 11:45 AM
  2. Combining data in multiple columns(all columns have same length)into one column
    By nzi0001 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 07-24-2014, 11:19 AM
  3. [SOLVED] Finding a formula that will consider length of cell and length of words
    By Mariah B in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-07-2013, 05:39 PM
  4. Adding length to For Next loop after starting
    By alcarl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2012, 02:41 PM
  5. Adding 0s in front of text to certain length
    By bruce71101 in forum Excel General
    Replies: 1
    Last Post: 09-28-2011, 01:42 AM
  6. Adding Data from Multiple-Length Columns
    By WangDoodle in forum Excel General
    Replies: 2
    Last Post: 11-09-2010, 04:14 PM
  7. Applying a formula to different length columns
    By Smiff1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2008, 03:27 PM

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