+ Reply to Thread
Results 1 to 23 of 23

How to set up reference variables?

  1. #1
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    How to set up reference variables?

    Hi All,

    I update a series of spreadsheets daily, and I'm betting that there's a faster/easier way to do some of the tasks I'm finding myself performing.

    I have to update a large group of simple formulas daily. These formulas would be something like:
    =(A11-A12)/A11
    I'll have to update a series of formulas just like this across a few dozen columns, and every day as I add a new row of data (next row in my example would be row 13), I have to go back through all my formulas so they reference the next two rows of data. For example, the next day's formula for my above example would be:
    =(A12-13)/A12

    I'm doing this 50 times a day, and I'm betting there's an easier way to set this up. Can anyone offer me a suggestion?

    Sincere thanks,
    C.J.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hi C.J. and welcome to the forum.

    Your question smells like you need a Named Range or even better a Dynamic Named Range in your formula somewhere.

    Read about them at:
    http://www.contextures.com/xlNames01.html or
    http://www.exceluser.com/explore/dynname1.htm

    If you supply a sample worksheet of what you have and need it is much easier to give a more specific answer.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Thank you, Marvin.

    I looked into those named ranges, and I'm not entirely sure that's what I need. I can be a little more specific about what I'm looking for, though.

    In my example, I illustrated this simple formula:
    =(A11-A12)/A11

    So, the parts of this formula that are changing daily are the cell numbers. Today the cells I'm working on are A11/A12, but tomorrow it'll be A12/A13. In other words, the cells increment daily, and this happens for about 20 different rows of data.

    So, what I'm trying to do is find a way to replace the "11" and "12" with some type of variable that I can update daily. Then, instead of updating the formulas daily, I can simply update some other tool or piece of information with the rows the formulas are to use that day, and the spreadsheet will pick up the correct values without me having to update 30 different formulas. See, all the formulas work on the same two rows daily, so if I had one reference point for these formulas to use, I could point them all to the correct two cells to work on at the same time.

    I hope that made sense. I can't insert the actual spreadsheet I'm working on for security reasons, but that's basically how this spreadsheet works.

    Sincere thanks,
    C.J.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hi C.J.

    How about a formula that uses the
    Please Login or Register  to view this content.
    function?
    Then when you add data it will always use the date of today to pick up which row.

    Another way may be to use the
    Please Login or Register  to view this content.
    function.

    I'm blindly guessing without having a sample to see what you really need. How about creating a sample and attaching it, if you are still stumped.

  5. #5
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Thanks, Marvin ... and your'e correct. An example is needed. I put together a little spreadsheet that illustrates what it is I'm trying to do. See attached:

    Sample Excel Spreadsheet.xls

    As you look at the formulas in row 1, I can explain what it is I have to do every day. I'll have to add a new row of data every morning. For example, tomorrow I'll be updating row #10. At that point, I'll go back in and edit the formulas. For example, the formula in row B1 will change from:
    =(B8-B9)/B8

    to:
    =(B9-B10)/B9

    This spreadsheet is just a sample. I actually have to update around 50 of these formulas daily. See, I really just want to have some mechanism to change the row #.

    It doesn't seem like there's a simple way to do this in Excel, though. Any ideas?

    Sincere thanks,
    C.J.

  6. #6
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    I think a better way to have stated this question would have been:

    How do you make a variable out of row #'s?

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hi,

    Have you found the function in excel of "=Row()" which will return the row number of the cell it is in?

  8. #8
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Quote Originally Posted by MarvinP View Post
    Hi,

    Have you found the function in excel of "=Row()" which will return the row number of the cell it is in?
    No, I hadn't looked at that function. How would I incorporate that into the formulas in my example spreadsheet?

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Look at the Grade Examples on http://www.contextures.com/xlFunctions02.html

    The important part is the "True" for the Range_Lookup argument. You don't want exact match. You want the Lookup to move down the list and run into a value larger than what is being looked for. NOTE - you must have your list sorted for this type to work correctly.

  10. #10
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Thanks, Marvin!

    This is interesting, but regretfully, it still doesn't give me what I was looking for. I'm not able to sort the lists I'm working with.

    I don't think there's an easy way to do this. The individual I took this process over from told me they tried finding an easier way to update these spreadsheets but were unsuccessful. I think I understand why now.

  11. #11
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hi cjhund,

    I think I have an answer for you. The formula involved the last row and the next to last row of values entered. I'm hoping you don't have any blanks. Then you can use the Count function with the Offset function and get the formula. See the attached with a formula in cell B1 of:
    Please Login or Register  to view this content.
    that you can pull across for all the other columns.

    I hope this does it. If there are blanks in the numbers in any column we will need to rethink the formula above.

    You shouldn't need to retype those formulas each day.
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: How to set up reference variables?

    Maybe develope a UDF using Marvin's formula to use each day?
    Then it is just a matter of typing in the name of the UDF rather than the whole string of nested formulas.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  13. #13
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    HEY - My formula works if there are no blank cells in a column of numbers (up to 3000 rows).

    If this didn't work for him my next attempt was to twiddle with Dynamic Named Ranges to see if I could arrive at the LastRow and build a formula instead of using a UDF. A UDF was going to be my last and final attempt. Now we need to see if he comes back to see THE answer. What if he gave up and never visits back again? Sad!

  14. #14
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Quote Originally Posted by MarvinP View Post
    HEY - My formula works if there are no blank cells in a column of numbers (up to 3000 rows).

    If this didn't work for him my next attempt was to twiddle with Dynamic Named Ranges to see if I could arrive at the LastRow and build a formula instead of using a UDF. A UDF was going to be my last and final attempt. Now we need to see if he comes back to see THE answer. What if he gave up and never visits back again? Sad!


    I'll be coming back to visit!

    Thanks, Marvin. Let me give that a show and see if it works.

    C.J.

  15. #15
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Marvin, THANK YOU! That works perfectly, and you just saved my sanity!

    C.J.

  16. #16
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Marvin ... I hate to push my luck, but since that last formula worked so well, I thought I'd bring up the next batch of formulas I have to update. They are very similar to the ones which I just replaced with your formula. An example would be:

    =SUM(B17:C17)

    Very simply, adding the last two entries from two separate columns together. And again, this columns get updated with a new row of data daily.

    I'm playing with the formula you gave me, seeing if I can modify for this SUM formula, but so far I haven't had any luck. Maybe your formula only can work on a single column of data?

    Sincere thanks,
    C.J.
    Last edited by cjhund; 04-15-2011 at 11:12 AM.

  17. #17
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hey - no luck involved. You just need to do a simple example. My formula depends on the Count and Offsett fuctions.

    Count will tell how many numbers are in a range. I expect you to not have any blanks or non-numbers in the cells being in the range

    The Offset is then used starting from the 3rd row and going down the number of numbers found in the count. The third argument of the offset function will move to the right or left. If you want to pick up the number to the right of the current column then make this number a 1 instead of zero.

    See the formula in the attached in cell B3 for the formula of:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  18. #18
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to set up reference variables?

    @MarvinP

    Going back a few posts - I know your formula works BUT because OFFSET() is volatile may I suggest:

    In B1 dragged across:

    Please Login or Register  to view this content.
    instead of:

    Please Login or Register  to view this content.

    EDIT: May I further suggest this for OP's latest request

    =SUM(INDEX(B$4:C$3000,COUNT(B$4:B$3000),0))

    instead of

    =SUM(OFFSET($B3,COUNT(B4:B19),0),OFFSET($B3,COUNT(B4:B19),1))
    Last edited by Cutter; 04-15-2011 at 12:45 PM.

  19. #19
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hi Cutter,

    True and I owe you one. Or the OP owes you one.
    How would you do the sum of the last value in column B and the same row in Col C using Index? Give him an answer for that one too.

    I think I was on the Offset midset as I was working toward a Dynamic Named Range for him and that was going to be the next step.

  20. #20
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to set up reference variables?

    Darn

    I was waiting for you to respond but I thought you might be elsewhere so I edited my post to add a suggestion for his latest request.

  21. #21
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How to set up reference variables?

    Hi Cutter,

    I guess this is a little bit of different ways of doing stuff. DO dislikes volitile and directs us to not use Offset if possible.
    Watersev likes to use multi line code using the ":"
    shg likes i, j, k as variables.
    I like Cells(Row, "A") but many others like Range("A:" & Row).

    When I first realized Count() was a way to get to the last row, I considered Count of a 2 column range and realized that wouldn't work. I guess this led me to sticking with an Offset instead of Indirect.

    Thanks again for a different/better way to do this problem.

  22. #22
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How to set up reference variables?

    DO dislikes volitile and directs us to not use Offset if possible.
    Yep - he rapped my knuckles for that some time ago. So it has stuck in my mind.

    Thanks again for a different/better way to do this problem.
    You're very welcome. Glad to help.

    I'm off now to dethatch my lawn. #1 on my 'Too Whacked To Do" List.

  23. #23
    Registered User
    Join Date
    04-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: How to set up reference variables?

    Thanks again for all the help!

    I haven't tried the INDEX version of the formula, but the OFFSET version works great for what I need to do.

    Thanks,
    C.J.

+ 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