+ Reply to Thread
Results 1 to 9 of 9

Sheets: Using Text from Another Cell as a Parameter for a Function

  1. #1
    Registered User
    Join Date
    10-16-2017
    Location
    Utah, United States
    MS-Off Ver
    2016
    Posts
    11

    Question Sheets: Using Text from Another Cell as a Parameter for a Function

    Hi, I'm working on a few different projects, which all have one unusual thing in common: I'm trying to pass the text contents of a cell to a function/formula in a different cell. I included a truncated version of one of these projects as an attachment, which I'll refer to in this post.

    Over to the right of this spreadsheet, I'm using COUNTIF to count the number of times a name occurs in the larger range. Right now, I just have everything hard-coded, e.g. Lucy in one cell, and then =COUNTIF($A$2:$F,"Lucy") in the cell beside it. But what I'd like to do is set up the formula such that it will automatically reference the string contents of the cell beside it. Something like =COUNTIF($A$2:$F, at H11), although that's obviously not the syntax that will properly pass the contents of cell H11 as a parameter to the COUNTIF function.

    It is entirely possible that what I'm trying to do is, well, impossible, not something that can be done in Google Sheets. I just felt like it should be something that should be possible, and so I wanted to ask. I've tried to search for stuff like "pass cell value to function" or "use cell contents in formula" but I haven't had any luck so far.
    Attached Files Attached Files
    Last edited by SpookyNoodle; 08-27-2021 at 08:43 PM.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Try it this way in I2:

    =COUNTIF($A$3:$D$26, H2)

    then copy down. This works in Excel, so I would assume it should also work in Google Sheets as it is fairly basic.

    Hope this helps.

    Pete

  3. #3
    Forum Contributor
    Join Date
    12-17-2013
    Location
    ON, Canada
    MS-Off Ver
    MS 365
    Posts
    171

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Have a look at the link. A formula in K2 to extract all the unique names, and a formula in L2 counts the number of times the name appears. Hope this is what you're after.

    https://docs.google.com/spreadsheets...it?usp=sharing

  4. #4
    Registered User
    Join Date
    10-16-2017
    Location
    Utah, United States
    MS-Off Ver
    2016
    Posts
    11

    Lightbulb Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Quote Originally Posted by Pete_UK View Post
    Try it this way in I2:

    =COUNTIF($A$3:$D$26, H2)

    then copy down. This works in Excel, so I would assume it should also work in Google Sheets as it is fairly basic.

    Hope this helps.

    Pete
    I could have sworn I already tried this, at that it didn't work, but when I do it now, it works exactly as expected! I don't know what sorts of funky witchcraft you did, but I'll take it!

    Quote Originally Posted by Flyboy65 View Post
    Have a look at the link. A formula in K2 to extract all the unique names, and a formula in L2 counts the number of times the name appears. Hope this is what you're after.
    This wasn't really what I meant, but it works much better at accomplishing the original task! This is super neat, thanks so much for showing me this.

  5. #5
    Registered User
    Join Date
    10-16-2017
    Location
    Utah, United States
    MS-Off Ver
    2016
    Posts
    11

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Okay, I got 2 really good solutions for my bafflingly-simple problem, but there's something else. In another project, I'm trying to reference data from a separate spreadsheet: =average(filter(Rocketbelt!F2:F, Rocketbelt!B2:B=B2))

    Now, the contents of cell A2 happen to be the string "Rocketbelt", but there are spreadsheets with different names that I also would like to reference, and those names are just in the A column of the sheet. Is there any way that I can alter this formula to automatically point to the correct spreadsheet, or would I need to just manually adjust it each time I'm referring to a new sheet?

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Do you have the INDIRECT function in Google sheets? You would use it like this:

    INDIRECT("'"&A2&"'!F2:F100")

    and:

    INDIRECT("'"&A2&"'!B2:B100")

    Hope this helps.

    Pete

  7. #7
    Registered User
    Join Date
    10-16-2017
    Location
    Utah, United States
    MS-Off Ver
    2016
    Posts
    11

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Quote Originally Posted by Pete_UK View Post
    Do you have the INDIRECT function in Google sheets? You would use it like this:

    INDIRECT("'"&A2&"'!F2:F100")

    and:

    INDIRECT("'"&A2&"'!B2:B100")
    You are a genius and a scholar! By using INDIRECT I can concatenate the string values, and INDIRECT still returns the ranges that FILTER needs to do its thing!

    It took me some fiddling, but what had previously been hard-coded as:

    =average(filter(Rocketbelt!$H$2:$H, Rocketbelt!$B$2:$B=B2))

    with me having to change the string every 6 lines or so can now be written as:

    =average(filter(INDIRECT("'"&A2&"'!$H$2:$H"), INDIRECT("'"&A2&"'!$B$2:$B")=B2))

    and when I drag it across the entire column, everything works out exactly as it should! I can't thank you enough, but I'll say it anyway: thanks!

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Glad to help, and thanks for marking the thread as Solved.

    You might also like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

  9. #9
    Registered User
    Join Date
    10-16-2017
    Location
    Utah, United States
    MS-Off Ver
    2016
    Posts
    11

    Re: Sheets: Using Text from Another Cell as a Parameter for a Function

    Quote Originally Posted by Pete_UK View Post
    You might also like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).
    Done and double-done, for everyone's who's posted replies here.

+ 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. Parameter Query that takes parameter value from Excel Cell
    By Aquamore in forum Access Tables & Databases
    Replies: 1
    Last Post: 01-23-2014, 03:43 PM
  2. Replies: 0
    Last Post: 11-12-2013, 03:57 AM
  3. [SOLVED] How to access cell values in VBA Function using Range parameter
    By HooGolfer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2012, 04:14 PM
  4. Replies: 11
    Last Post: 03-27-2012, 02:47 AM
  5. How to set joint parameter for a few sheets?
    By markos17 in forum Excel General
    Replies: 0
    Last Post: 01-14-2011, 04:56 AM
  6. to update all sheets with a check using parameter of first sheet
    By atksamy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2008, 09:25 AM
  7. [SOLVED] Cell contents as the 'lookup value' parameter in HLOOKUP function
    By EMarre in forum Excel General
    Replies: 3
    Last Post: 08-30-2005, 11:05 AM
  8. [SOLVED] Defining new function with cell range parameter
    By NormD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2005, 12:06 PM

Tags for this Thread

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