+ Reply to Thread
Results 1 to 11 of 11

Offset based on cell reference

  1. #1
    Registered User
    Join Date
    05-14-2009
    Location
    Bay Area, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Offset based on cell reference

    Tried searching for this, but I'm not even sure what to search for.

    Here's what I would like to do:
    1. Let's say A1 has the simple formula =B4
    2. I want A2 to be whatever A1 refers to offset by x-columns and y-rows (say x is 1 and y is 1 for this example), i.e. A2 would be whatever is in cell C5

    What formula would I use to do this? I tried playing around with offset, address and indirect without much luck.

    Thanks!!!
    Last edited by scottjn; 06-27-2011 at 12:29 PM.

  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: Offset based on cell reference

    If A1 has the formula

    =B4

    and NOT the formula

    ="B4"

    then there is no built-in Excel formula that will tell you what cell A1 is referring to.

    This could be done using a user-defined function written in VBA. It would be something like this:

    Please Login or Register  to view this content.
    If a cell refers to one other cell, as in your example, you can strip off the leading "=" and then use INDIRECT and OFFSET on the result.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Offset based on cell reference

    Using Defined Names
    With your cell selected as A2,
    Defined Name = GetFormula
    Refers to: =GET.CELL(6,Sheet1!A1)

    Then in A2 (with A1 containing =B4)
    =OFFSET(INDIRECT(MID(GetFormula,SEARCH("=",GetFormula)+1,5)),1,1)
    Those last two 1's can be replaced by cell references to offset rows and columns.
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    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: Offset based on cell reference

    Hey ChemistB, that's pretty slick. I have never seen GET.CELL before and it doesn't seem to work as a plain vanilla formula. How does this work in the context of a named formula?

  5. #5
    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: Offset based on cell reference

    Well, I seem to have sorted it out. This is an old Excel 4.0 macro call, which apparently is still supported if you use it in a named formula but not on a worksheet. Here the Help entry from Microsoft. The complete 4.0 macro Help file can be downloaded this page: http://support.microsoft.com/default...S;Q128185&FR=1

    Code tags used to preserve formatting.
    Please Login or Register  to view this content.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Offset based on cell reference

    XL2007+: Use of XLM calls necessitates .xlsm save on which basis: use a UDF

  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: Offset based on cell reference

    Here is a mod to the UDF that more closely matches conventions for Excel functions.
    Please Login or Register  to view this content.
    If a cell refers to one other cell, as in your example, you can strip off the leading "=" and then use INDIRECT and OFFSET on the result.[/quote]

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Offset based on cell reference

    Yes, as you found out, it's an old macro 4 command that can still be used in defined names. I use them sometimes when verifying a spreadsheet to conditionally format formulas and/or locked/unlocked cells.

  9. #9
    Registered User
    Join Date
    05-14-2009
    Location
    Bay Area, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Offset based on cell reference

    Thanks, that does work. Although it is a bit cumbersome since I would like to do it for many cells and many worksheets. Thanks again.

    Quote Originally Posted by ChemistB View Post
    Using Defined Names
    With your cell selected as A2,
    Defined Name = GetFormula
    Refers to: =GET.CELL(6,Sheet1!A1)

    Then in A2 (with A1 containing =B4)
    =OFFSET(INDIRECT(MID(GetFormula,SEARCH("=",GetFormula)+1,5)),1,1)
    Those last two 1's can be replaced by cell references to offset rows and columns.
    Does that work for you?

  10. #10
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Offset based on cell reference

    The formula is relative so you can paste that into any cell within that spreadsheet. 6String's UDF is more versitile.

  11. #11
    Registered User
    Join Date
    02-25-2019
    Location
    Sana'a, Yemen
    MS-Off Ver
    Office 2016
    Posts
    1

    Re: Offset based on cell reference

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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