+ Reply to Thread
Results 1 to 14 of 14

Formula that correlates cell text to a sheet in workbook

  1. #1
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Formula that correlates cell text to a sheet in workbook

    Hello All,

    I'm working on a formula that will auto populate total payroll for different departments. I will use this to compare the current month to the previous month for each department within a single workbook. Both the previous month and current months payroll spreadsheets will be included in the workbook. I could write the code as, =sumifs(previous!D:D,previous!H:H,"=Management",previous!G:G,">600000") and rename each sheet to current and previous. I would rather not have to rename the sheets for ease of use, since there will be 12 of them per year and seeing each months named sheet will be less confusing for anyone else looking at the work.

    At the top of each chart on my analysis spreadsheet I name the columns of data Jan and Feb, for example, which is the same name as the sheet containing the payroll for each month. I would like the formula to recognize what I type in that specific cell and correlate it to the matching sheet to pull the info.

    In other words if I type Jan in a given cell, I want the macro to do =sumifs(Jan!D:D,Jan!H:H,"=Management",Jan!G:G,">600000"), where the sheet I import into the analysis workbook will be named Jan.

    Thoughts?

    Thanks in advance

    A side question, I condensed this code as the forum will not allow me to post a 'less than symbol'. Any thoughts why? I get a popup from securi firewall which our IT guy says is not our firewall.
    Last edited by the machine; 07-17-2018 at 11:16 AM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,935

    Re: Formula that correlates cell text to a sheet in workbook

    I would like the formula to recognize what I type in that specific cell and correlate it to the matching sheet to pull the info.
    Sound like a job for superm....oh wait, wrong 1 LOL

    You can do this with INDIRECT, something like this...
    =sumifs(indirect("'"&A1&"D:D!","'"&A1&"!H:H","Management","'"&A1&"!G:G",">600000")

    Although, using INDIRECT on full-column references could slow your file down, so consider restricting the range to 2-3 times what you think you would need (or just that table, if it wont grow at all)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Formula that correlates cell text to a sheet in workbook

    To address the "<" question. Put a space after it and you should be able to post using it.

    That's on our side (as in the forum).

  4. #4
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    Thanks for your help all.

    FD, can you explain what you mean by "using indirect on full column references will slow it down" The sheets for each month are around 160,000 lines long. My analysis worksheet has 20 departments, with 7 separate time codes, regular time, overtime, holiday, vacation, disabled, paid for not worked, and other. So this formula would be included on the analysis sheet 280 times.

    Is this not doable?

  5. #5
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    =SUMIFS(indirect("'"&D14&"D:D!","'"&D14&"!P:P","=Management"))

    I'm getting a 'you've entered too many arguments for this function' error

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,935

    Re: Formula that correlates cell text to a sheet in workbook

    Full-column references are like D:D, that is over 1 million rows, rather than $D$1:$D$160 000

    Try it this way then, I just typed that 1 here, looks like I was a bit inaccurate

    =sumifs(indirect("'"&A1&"!D:D",indirect("'"&A1&"!H:H"),"Management",indirect("'"&A1&"!G:G"),">600000")

  7. #7
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    Ok, now I'm just stuck with a #Ref error. I tried it on a fresh payroll worksheet.

    =SUMIFS(INDIRECT("'"&D14&"D:D!"),INDIRECT("'"&D14&"!H:H"),"=Management",INDIRECT("'"&D14&"!G:G"),">600000",INDIRECT("'"&D14&"!G:G")," < 610000")

    Cell D14 says Feb, the sheet name that contains the information is named Feb. Not sure what I'm missing.

    Thanks

  8. #8
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    disregard, I figured it out. missing the single quote in front of all the ! and the first one was after the D:D.

    Thanks for the help everyone

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,935

    Re: Formula that correlates cell text to a sheet in workbook

    Happy to help and thanks for the feedback

  10. #10
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    No worries,

    And while I have you here I thought of one thing I would like to modify with the formula. Each department has its own section on the analysis spreadsheet. So the management department I am pasting into the management section 7 times for each pay type. When I go to a different department, say President, I have to update the "=Management" to "=President". Not a huge issue but it would save time if I could just copy the file to read

    =ROUND(SUMIFS(INDIRECT("'"&D$10&"'!D:D"),INDIRECT("'"&D$10&"'!P:P"),"READ THE INFO IN THE CELL THAT IS THE TITLE OF THE DEPARTMENT",INDIRECT("'"&D$10&"'!L:L"),">610000",INDIRECT("'"&D$10&"'!L:L")," < 620000"),0)

    The benefit to this method also will be if a department name changes, say to President's Office, I only have to update the department title in the section rather than 7 times in each formula.

    Thanks again for your help. I'll rep you again if I can

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,935

    Re: Formula that correlates cell text to a sheet in workbook

    Sure, you just need to reference the cell containing that, instead of hard-coding it.

    =ROUND(SUMIFS(INDIRECT("'"&D$10&"'!D:D"),INDIRECT("'"&D$10&"'!P:P"),$E10,INDIRECT("'"&D$10&"'!L:L"),">610000",INDIRECT("'"&D$10&"'!L:L")," < 620000"),0)

    where E10 would contain the dept name

  12. #12
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    ha, I did that and it didn't work. Maybe I deleted a comma on accident.

    Thanks again

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,935

    Re: Formula that correlates cell text to a sheet in workbook

    maybe upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.

  14. #14
    Registered User
    Join Date
    04-24-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    83

    Re: Formula that correlates cell text to a sheet in workbook

    FD, what I meant was that I initially tried that suggestion and it didn't work. It did when I tried it again, I must have initially deleted something I wasn't supposed to.

    I ran in to one final problem with the formula. Just needs to display an area where the department is blank. I tried =ROUND(SUMIFS(INDIRECT("'"&D$10&"'!D:D"),INDIRECT("'"&D$10&"'!P:P"),$E10,INDIRECT("'"&D$10&"'!L:L"),">610000",INDIRECT("'"&D$10&"'!L:L")," < 620000"),0)

    where E10 is a blank cell but it just returns 0, and there are for sure blanks in the file. The total should be $145

    Thanks


    disregard. "" works wonders when used properly.

    ::facepalm::
    Last edited by the machine; 07-19-2018 at 12:01 PM.

+ 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. Replies: 1
    Last Post: 04-27-2017, 06:58 AM
  2. Populating a cell with a formula that references a previous sheet in that workbook
    By fatesdefiance in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2016, 05:09 PM
  3. How to get cells with static data to stay in the row it correlates to
    By romeshomey in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-23-2015, 12:29 AM
  4. [SOLVED] Cell A1 contains specific #s, place X under row/column that correlates to that #
    By marshak in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-19-2013, 02:43 AM
  5. Indirect Formula to return Text from one sheet to cell in another sheet
    By lou031205 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-04-2007, 02:51 PM
  6. Replies: 3
    Last Post: 08-23-2007, 04:47 PM
  7. Replies: 2
    Last Post: 04-08-2007, 02:21 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