+ Reply to Thread
Results 1 to 8 of 8

Change column reference within a range by numeric position within the range

  1. #1
    Registered User
    Join Date
    12-19-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Change column reference within a range by numeric position within the range

    Hi

    I'm looking for a way to change the column reference in a formula by translating a numeric value into the column reference position in a range. For example;

    =COUNTIF($O:$O,"Yes")

    I also have a column which contains the relative position of the column used in the above formula, so that column O would equate to a value of 1. What I want to do is alter the column reference in the formula by the numerci value in a cell, when copied down, so that if cell value = 2 the effect of the formula would be =COUNTIF($P:$P,"Yes"), and if cell value = 3, =COUNTIF($Q:$Q,"Yes") etc. etc.

    I guess this would almost be a reverse of the COLUMN function, where a numeric value is translated into a column address.

    Thanks in advance

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Change column reference within a range by numeric position within the range

    this would be INDIRECT
    I'd personally use it here together with CHR function. If your cell containing "how many columns right from O:O" is A1:

    Please Login or Register  to view this content.
    of course it works only until Z column

    If its too little - use ADDRESS to get column name

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,028

    Re: Change column reference within a range by numeric position within the range

    Here, try this:

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


    Where A1 is your column offset (0 for O column, 1 for P column, 2 for Q column etc)

    Edit: And work beyond Z
    Never use Merged Cells in Excel

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Change column reference within a range by numeric position within the range

    =COUNTIF(INDEX(O:XFD,0,a1),"yes") where a1 is your number fill down ,no indirect or offset needed
    but do you really need a range that big?
    it is always best to limit the range to what you are likely to need and to avoid whole column references like A:B when $a$1:$b$5000
    would suffice
    Last edited by martindwilson; 12-19-2013 at 07:12 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    12-19-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Change column reference within a range by numeric position within the range

    Lovely stuff.

    Tried both zbor and martindwilson's methods, and they both worked perfectly. Sorry Kaper, I didn't try yours (although I'm sure it works too), purely becuase the formual string was longer than the other 2.

    Many thanks

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Change column reference within a range by numeric position within the range

    you dont really need a column numbered 1,2,3,4,5 and so on
    =COUNTIF(INDEX(O:XFD,0,ROWS($a$1:a1)),"yes") would do away with that column

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,028

    Re: Change column reference within a range by numeric position within the range

    I think you missing $ but if he need them all he just need =COUNTIF(O:O,"Yes") and move it to the right.
    I understood he need to change column number, not get them all.

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Change column reference within a range by numeric position within the range

    ops original request
    by the numerci value in a cell, when copied down,
    so i assume op has a list down
    now it maybe that that column goes 1,3,5,7,9...... so that could be done as well but if it was 1,2,5,9,10 then thats a different matter
    Last edited by martindwilson; 12-19-2013 at 08:26 AM.

+ 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. Replies: 4
    Last Post: 09-04-2013, 12:30 AM
  2. reference a position in a range
    By opeyemi1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-02-2010, 08:22 PM
  3. Percentage Change to Selected Numeric Range
    By ken mossman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2009, 07:28 PM
  4. Replies: 1
    Last Post: 11-11-2009, 01:08 AM
  5. Find the POSITION IN A RANGE of text in a string that matches value(s) in a range
    By Cornell1992 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2006, 03:25 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