+ Reply to Thread
Results 1 to 17 of 17

Formula to return cell value based upon cell reference

  1. #1
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Post Formula to return cell value based upon cell reference

    I have a large spreadsheet where I would like to reference a cell's name to return a value for a different cell. For example:

    Excel sample.png

    In the above table cell A2 references cell J2 and returns its value. How could I have cell B2 return a value for cell K2 by referencing the line number in cell A2. Note: Usually the line that I am returning the data to is not the same as the line I am getting it from, but the cell reference is always the same line. In otherwords if the reference for A2 is J7, then B2 would be K7, or if A2 is J85, then B2 would be K85.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Formula to return cell value based upon cell reference

    If the values in column J are unique, you can use VLOOKUP.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If the values in column J are not unique, I think you will need a VBA function. I do not know of any Excel worksheet function that can read the formula in another cell.




    An image attachment has very little value. It will be much easier to understand your problem if you provide your file, and it's easier than taking a screenshot first then attaching that.
    To attach a file:
    1. Under the text box where you type your reply click the Go Advanced button.
    2. In the next screen look above the reply box and click the "paper clip" icon. You will get a pop-up screen.
    3. In the pop-up, click Add then Select to select a file from your local drive
    4. Click the Upload button to upload the file
    5. Click Done to attach it.

    It will be displayed as an attachment underneath your post text. Alternatively as the last step you can click the Insert Inline button and a hyperlink to the file will be inserted directly into your post text in the spot where your cursor is set at the moment you click the button.

    Here are step-by-step instructions with screen shots
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    Thanks Jeff, but when I click on the Attachments icon, the Upload window does not open.

  4. #4
    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,933

    Re: Formula to return cell value based upon cell reference

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    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

  5. #5
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    Attached is my example. In the example columns D thru N have cell references in them. I would like to be able to enter only the
    reference in Column D and have formulas set to fill in the rest of the columns. Hope someone can help with this.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    Thanks Ford. I was able to upload my file and send it out.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Formula to return cell value based upon cell reference

    I could not figure out a way to do this without VBA; I know of no function that can return another cell's formula as a string. VBA solution attached. The way this works is that there is a user-defined function RowFromFormula that will take a cell as the argument, and read the formula in that cell and return the row referenced in that formula. Once you have that row, then you use INDEX to look up the value from the desired column using that row.

    The function expects the formula to look like =A1.If ForFromFormula tries to read the cell formula but can't determine a row number from it (for example, the formula is =SUM(A1:B2)) then you will get an error.

    I have installed this into your file.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    Thanks so much 6String. That looks like it will work!! You have saved me lots of time, and as we all know, Time is Money!

  9. #9
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Question Re: Formula to return cell value based upon cell reference

    Need some more help. I have never used VBA. I was able to copy your VBA formula from row to row in my sample spreadsheet. But when I
    tried to copy it to a new spreadsheet it looked like the attached. Do I need to enable VBA or something?
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: Formula to return cell value based upon cell reference

    You need to put the VBA code into your spreadsheet:

    Press Alt+F11 to open VBA editor

    Right click on panel on left-hand side

    "Insert" ==> Module

    Copy Code below into the right-hand panel

    Save file as .xlsm


    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    Thanks so much!! I need to learn this VBA stuff - LOL

  12. #12
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Unhappy Re: Formula to return cell value based upon cell reference

    I was able to insert the module into a sample Excel sheet, but when I tried to do it on the spreadsheet i need it in, it is not
    working correctly. The sheet is already an .xlsm sheet so that is not the problem. Please see the attached sheet and see if you
    can tell me why it is not working properly.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: Formula to return cell value based upon cell reference

    What value should be in D3? Based on the current value of "=X2" the results are correct (appears to be for JAN not FEB)..

    If you put for example =X113 in D3 then you get correct results

  14. #14
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    I don't know what happened but when I reopened it after letting it sit for a while everything was working!! Excel is a funny animal sometimes.

    Ok, here is another related question. If I wanted to get a sum for columns Z to AF based upon the line referenced in column D, what would the formula look like? For example, right now I manually type in the formula "=sum(z2:af2)" (where D3 is "=X2)", in every cell in column E. Can I use the VBA function you gave me somehow in the formula to give me the result?

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: Formula to return cell value based upon cell reference

    Untested code ... I could not see a SUM formula in column E
    Please Login or Register  to view this content.
    Enter formula below in cell ...

    =SumRowFromFormula($D3)
    Last edited by JohnTopley; 04-08-2016 at 02:52 PM.

  16. #16
    Registered User
    Join Date
    03-30-2016
    Location
    Oberlin, OH
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to return cell value based upon cell reference

    I tested it out on the spreadsheet. It seems to work. Thanks again John!!

  17. #17
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: Formula to return cell value based upon cell reference

    My pleasure.

    Can you please mark thread as solved ("Thread Tools" at top of first post).

+ 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. [SOLVED] Formula that changes answer cell based on numeric value in reference cell
    By dtinman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-28-2014, 12:41 PM
  2. [SOLVED] How to use LARGE to return a cell reference for use in OFFSET formula
    By TC1980 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-11-2013, 08:31 AM
  3. Macro to return a cell reference based on a seach criteria?
    By Al_O_L in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2012, 08:47 AM
  4. Replies: 3
    Last Post: 05-09-2012, 06:22 PM
  5. [SOLVED] return cell reference in a table based upon given lookup criteria
    By Travis in forum Excel General
    Replies: 3
    Last Post: 03-15-2006, 10:35 AM
  6. [SOLVED] Cell Formula reference to cell Based On third Cell Content
    By Gabriel in forum Excel General
    Replies: 0
    Last Post: 02-11-2005, 02:06 AM
  7. [SOLVED] formula to return the value of a cell based on a looked up true reference
    By sarah in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-02-2005, 05: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