Consulting

Results 1 to 9 of 9

Thread: Referece to Formulas R1C1

  1. #1

    Referece to Formulas R1C1

    Hello guys,

    I have to create a workbook and populate some formulas that have lookups to closed workbooks.

    I am trying to make the ranges for the lookup as dynamic as possible. I also want to use a R1C1 formula because it will allow me to populate several cells at the same time in one step. I can always put a regular formula in the first cells and the fill. But I would rather not do that.

    So the first thing I do is open my Reference workbook and load the addresses for the ranges I will be doing the lookup to. Once those ranges are in my string variables I would use them in my formula.

    The only problem is that If the formula references to a column before the the column I am putting the formula in then it comes with the negative value.

    Any ideas on how to do this?

    Thanks
    Last edited by fredlo2010; 02-19-2014 at 03:02 PM.
    Feedback is the best way for me to learn


    Follow the Armies

  2. #2
    Well this was actually me being silly.

    The formula works perfectly.

    I made a mistake when writing the path for the VLOOKUP I swapped positions for "!" and " ' " for the sheet name.

    Thanks for all the help.
    Feedback is the best way for me to learn


    Follow the Armies

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If your lookup is in the "wrong" order, use Index-Match
    =INDEX(A:A,MATCH(E1,B:B,0))
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Quote Originally Posted by mdmackillop View Post
    If your lookup is in the "wrong" order, use Index-Match
    =INDEX(A:A,MATCH(E1,B:B,0))
    Thanks a lot for the help but this is not the case. The lookup was in the correct order.

    I will be using Vlookups because the ranges are big (more than one column) so it will be easier to reference them like that. In my formulas which are complicated already.


    Thanks
    Feedback is the best way for me to learn


    Follow the Armies

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by fredlo2010 View Post
    I am trying to make the ranges for the lookup as dynamic as possible. I also want to use a R1C1 formula because it will allow me to populate several cells at the same time in one step.
    You can just as easily do that with an A1 formula, like so

    Range("M1:M20").Formula = "=IF(A1>20,A1*B1,A1)"
    and Excel will adjust them all.

    Where R1C1 is really useful is in allowing you to embed variables in the formula and use numeric values, noit having to convert to column letters.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop View Post
    If your lookup is in the "wrong" order, use Index-Match
    =INDEX(A:A,MATCH(E1,B:B,0))
    OR

    =VLOOKUP(E1,CHOOSE({1,2},B:B,A:A),2,FALSE)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Quote Originally Posted by xld View Post
    You can just as easily do that with an A1 formula, like so
    Range("M1:M20").Formula = "=IF(A1>20,A1*B1,A1)"
    and Excel will adjust them all.
    Mind opening I always thought It could be done only with R1C1 formulas.

    Quote Originally Posted by xld View Post
    Where R1C1 is really useful is in allowing you to embed variables in the formula and use numeric values, noit having to convert to column letters.
    I am finding the specific header, returning the column number and then inputting the value in my formula.

    Thanks a lot for the help guys

    Alfredo
    Feedback is the best way for me to learn


    Follow the Armies

  8. #8
    One last thing to add here. I had to work on Saturday fixing all my VLookUps formulas after my code broke when trying to implement a new change and I spent 3 hours on Friday trying to see what was wrong; it was of course the column numbers in my Lookups.

    I changed them all to Index-Match combinations and now the only thing I have to worry about is if the headings for my file change(most likely they will not) I also broke free from static column structure where all columns had to be in an specific order to be accessed; so now I can have actual data to the left and all auxiliary formulas to the left.

    This took me a whole morning of migration and the creation of a small new class to help me keep the data referencing organized; but it's so much better.

    I though I would share this here; because this looked to me like a classic case of "I told you" lol

    Thanks
    Feedback is the best way for me to learn


    Follow the Armies

  9. #9
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    UDF:

    'Name is acronym of function Column 2 Index
    Public Function fC2I(array_tableFirstColumn As Range, ColIndex As Range)As Long
      fC2I = (ColIndex.Column - array_tableFirstColumn.Column) + 1
    End Function
    Usage:
    Col_index_num "= fC2I(" & Select Cell in any row in first column of table_array, & comma, then select cell in any row in index_column & ")"
    =VLOOKUP("XYZ",G2:W999,fC2I($G$1,$H$1),1)
    Where you want the return from the second column of the table G:W
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •