+ Reply to Thread
Results 1 to 15 of 15

Relative relationship to current cell (with formula)

  1. #1
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Relative relationship to current cell (with formula)

    I have a cell H24 with the following formula:

    Please Login or Register  to view this content.
    Is it possible instead of saying B24, to say something like "6 columns to the left" or would that impact the indirect statement?

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Relative relationship to current cell (with formula)

    Hi,
    That's basically what B24 means in a formula in H24. Are you having an issue with it?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Relative relationship to current cell (with formula)

    Quote Originally Posted by mainemojo View Post
    Is it possible instead of saying B24, to say something like "6 columns to the left" or would that impact the indirect statement?
    Pardon me if this is something you already know but it sounds like you arent totally clear on relative vs absolute references.

    A reference is made of 2 basic parts, the obvious being column letter and row number, ie: B24. There is however 4 states a reference can be in, represented by dollar signs in specific places in a reference:

    B24 = relative reference
    $B24 = absolute column, relative row
    B$24 = relative column, absolute row
    $B$24 = absolute reference

    So whats the meaning? Typically references are relative, meaning as the formula gets filled up/down/left/right from its origin, the reference changes relative to the origin too. In other words putting =D4 into C3 and then filling or copying that formula into B2 would result in the relative change of the formula in B2 =C3, having adjusted the reference up a row and over to the left a column as our "new" formula is also up 1 row and over to the left 1 column from where we originally got it from.

    This is a great benefit most of the time, but sometimes what you referenced in a formula shouldnt change when the formula is filled. The $ sign "anchors" the part of the reference to its right so that it doesnt change. In other words it makes it absolute. So a fully absolute reference doesnt change at all. As seen in my list above you can anchor only the column or only the row as well.

    So to answer your question, if your reference B24 is 6 columns to the left of where your formula is, then no matter where you fill the formula the reference will change to a reference 6 columns to the left, except in cases in which thats not possible (like if you suddenly paste that formula into cell C2, well there arent 6 columns to the left of column, this wont work then and you will get a REF error.)
    Last edited by Zer0Cool; 06-05-2018 at 10:14 AM.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  4. #4
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Relative relationship to current cell (with formula)

    xlnitwit ... Yes. I have a bunch of merged cells so I can't copy the formula with auto fill. The next cell down in the column may have a reference of B28 (because H24 is the merge of four rows H24, H25, H26, and H27). So in the next cell in the column, the formula would be:

    Please Login or Register  to view this content.
    Instead of using a static cell reference such as "B28", I'd rather have it say "the value of the cell 6 columns to the left of the current cell". I can do that if I use a formula such as:

    Please Login or Register  to view this content.
    But how would I incorporate that code into what I'm trying to do? My guess was something like:

    Please Login or Register  to view this content.
    But that is plagued with errors!
    Last edited by mainemojo; 06-05-2018 at 10:57 AM.

  5. #5
    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,208

    Re: Relative relationship to current cell (with formula)

    Don't merge cells: it is the cause of so many problems( as you are discovering!).

    And it really is helpful if we have a workbook to help with getting the correct formulae and being able to test them.

    Attach a sample workbook (not image).so that we do not have to manually key in your data to do a testing.

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Relative relationship to current cell (with formula)

    I have suggested this before, and not got any positive feedback. The statement "the value of the cell 6 columns to the left of the current cell" sounds to me like a perfectly good relative R1C1 reference. In R1C1 notation, same row 6 columns to the left is simply RC[-6]. The INDIRECT() function can handle R1C1 references by using the optional A1 argument https://support.office.com/en-us/art...1-92b6306fa261 Something like =INDIRECT("RC[-6]",FALSE) should return the value from the cell in the same row and 6 columns to the left of the cell with the formula.

    For more information about using R1C1 notation, see this help file: https://support.office.com/en-ca/art...es_in_formulas
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Relative relationship to current cell (with formula)

    Quote Originally Posted by mainemojo View Post
    xlnitwit ... Yes. I have a bunch of merged cells so I can't copy the formula with auto fill. The next cell down in the column may have a reference of B28 (because H24 is the merge of four rows H24, H25, H26, and H27). So in the next cell in the column, the formula would be:

    Please Login or Register  to view this content.
    If you copy and paste the formula from H24 to H28, it will automatically adjust to use B28 instead of B24. I can't see what your actual issue is here- the formula already does exactly what you are asking, and achieves exactly the same as =OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0,-6).

  8. #8
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Relative relationship to current cell (with formula)

    John - unfortunately, this was a hand-me-down spreadsheet. It has too much data to un-merge cells. Uploaded an example.

    MrShorty - I understand cell references. My question is related to cell relationship. I want to take the formula, copy and paste into every cell in row H (remember, the cells are not always sequential such as H24, H25, etc, but more like H24, H28, H31, etc)

    xlnitwith - I know that the offset formula gets me partially what I want. My question is how do I incorporate it into my isblank(indirect formula?

    Using my attached example, I want to be able to copy the exact formula from Primary!H2 to Primary!H4 without any changes.
    Attached Files Attached Files

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Relative relationship to current cell (with formula)

    I don't understand the problem.
    That's exactly how the formula will work when filled down (regardless of the merged cells)

    If H24, H25, H26, and H27 are merged
    And then H28 H29 H30 and H31 are merged...

    Put this formula in H24
    =IF(ISBLANK(INDIRECT(B24 & "!B12")),"",INDIRECT(B24 & "!B12"))

    And drag it down
    H28 becomes
    =IF(ISBLANK(INDIRECT(B28 & "!B12")),"",INDIRECT(B28 & "!B12"))


    Is that not the desired result?

  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,208

    Re: Relative relationship to current cell (with formula)

    Dragging down will not work if the merged cells are different sizes (Ranges) as per your posted file.

    H4 is H4,H5,H6 whereas H2 is H2,H3

  11. #11
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Relative relationship to current cell (with formula)

    Jonmo1, it kind of is. The problems that I run into is what John was talking about earlier (and again while I was typing this out) - the merged cells. Earlier when I tried it, I got the error "To do this, all the merged cells need to be the same size". So if I drag it from a cell that is 4 merged rows to another that is 4 merged rows, it works. If I try dragging it to a cell that is 3 or 5 merged cells, then I get the error.

  12. #12
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Relative relationship to current cell (with formula)

    Instead of 'Dragging' down.

    Select the entire range (all cells of both merged ranges)
    Re-Enter the formula as if in the first cell and press CTRL + ENTER

    H2 and H3 are one merged range
    H4 H5 and H6 are a second merged range

    Highlight the whole range, H2:H6
    Put in the formula
    =IF(ISBLANK(INDIRECT(B24 & "!B12")),"",INDIRECT(B24 & "!B12"))
    DO NOT PRESS ENTER
    Instead, press CTRL + ENTER

  13. #13
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Relative relationship to current cell (with formula)

    Wow! That works almost perfectly! The one part it doesn't work is where the control is 7.10. The cell format is set to a two decimal number. The cell shows "7.10", but the formula bar shows "7.1" and the H cell with the formula shows #REF! (assuming because it can't find a worksheet named "7.1" as it is "7.10"). Do I need something like a ROUNDA?

  14. #14
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Relative relationship to current cell (with formula)

    If they are all 2DP, you might use
    =IF(ISBLANK(INDIRECT("'"&TEXT(B24, "0.00") & "'!B12")),"",INDIRECT("'"&TEXT(B24, "0.00") & "'!B12"))

  15. #15
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Relative relationship to current cell (with formula)

    That one works perfectly! The way I was originally thinking of fixing it was using the FIXED function or #s instead of zeros. Either way, your formula works perfectly and is much shorter than the ones I was playing around with. 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. how do i make the VBA macro relative to current workbook?
    By exceldrdr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-16-2018, 10:42 AM
  2. [SOLVED] Lock a range of cells base on current date relative to cell reference
    By egchristensen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2015, 05:11 PM
  3. VBA to insert row, copy formula from above does not keep relative relationship
    By Royzer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2012, 11:07 AM
  4. Referencing relative cells (current row)
    By jirib in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2011, 02:46 PM
  5. COUNTIF and relative offsets from current cells
    By mikejc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-16-2011, 04:08 AM
  6. check if a range is blank relative to current cell in vba
    By sark666 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2009, 10:37 PM
  7. Wildcard in path- relative to current sheet
    By kevlar3d in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-05-2008, 06:05 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