+ Reply to Thread
Results 1 to 8 of 8

Assigned value to cell based on two references

  1. #1
    Registered User
    Join Date
    05-28-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Assigned value to cell based on two references

    Sorry, I know the title may be a bit ambiguous and general, but I can't think of an easy way to describe my problem!

    I currently have a chunk of data, to which I'm trying to assign a group, and then count how many occurences there are of the said group. I'll try and explain a little better in a table..... As an example, my data follows this pattern (which is a simplified form of the actual data):


    1 a
    1 a
    3 b
    6 a
    4 a
    4 b
    4 a
    2 b

    The two groups are "a" and "b". If a number in the first column is followed by a "b" in the second, all occurences of that number need to be assigned a "b". So if there are multiple occurence, 2 of which are "a", and 1 "b", they all need to be assigned "b". As an example based on the above data, I need it to read:

    1 a
    1 a
    3 b
    6 a
    4 B rather than a
    4 b
    4 B rather than a
    2 b

    I've been messing with IF statements with AND and OR's, and trying to think my way round a VB solution if needed, but drawing a blank! I hope I've explained it well enough, any help would be greatfully received!
    Last edited by J-Tin; 10-15-2013 at 09:57 AM. Reason: solved

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Assigned value to cell based on two references

    Hi,

    Assuming that the data you give above is in the range A2:B9, entering this formula in C2 and copying down will give a column containing the 'corrected' letters for each number:

    =IF(ISNUMBER(MATCH(A2&"b",INDEX($A$2:$A$9&$B$2:$B$9,,),0)),"b","a")

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    05-28-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Assigned value to cell based on two references

    Thank you so much, been racking my brains for ages and it was a relatively simple solution thanks!

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: [Solved] Assigned value to cell based on two references

    You're welcome.

  5. #5
    Registered User
    Join Date
    10-14-2013
    Location
    Saturn
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Assigned value to cell based on two references

    Quote Originally Posted by XOR LX View Post
    Hi,

    Assuming that the data you give above is in the range A2:B9, entering this formula in C2 and copying down will give a column containing the 'corrected' letters for each number:

    =IF(ISNUMBER(MATCH(A2&"b",INDEX($A$2:$A$9&$B$2:$B$9,,),0)),"b","a")

    Regards
    Question: What does INDEX($A$2:$A$9&$B$2:$B$9,,) do? As far as I can tell from evaluating the formula step by step, it creates an array with concatenated pair-wise number and letter. Is the INDEX function only to create the array to feed into MATCH without using array function?

    I came up with a similar solution using array function:
    =IF(OR(A2&"b"=$A$2:$A$9&$B$2:$B$9),"b","a") CTRL+SHIFT+PLUS

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: [Solved] Assigned value to cell based on two references

    "Question: What does INDEX($A$2:$A$9&$B$2:$B$9,,) do? As far as I can tell from evaluating the formula step by step, it creates an array with concatenated pair-wise number and letter. Is the INDEX function only to create the array to feed into MATCH without using array function?"

    Yes. Precisely that.

    Generally, if a non-array solution can be generated (using e.g. INDEX) then it is, for various reasons, to be considered preferable to the array version.

    Regards

  7. #7
    Registered User
    Join Date
    10-14-2013
    Location
    Saturn
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: [Solved] Assigned value to cell based on two references

    Quote Originally Posted by XOR LX View Post
    "Question: What does INDEX($A$2:$A$9&$B$2:$B$9,,) do? As far as I can tell from evaluating the formula step by step, it creates an array with concatenated pair-wise number and letter. Is the INDEX function only to create the array to feed into MATCH without using array function?"

    Yes. Precisely that.

    Generally, if a non-array solution can be generated (using e.g. INDEX) then it is, for various reasons, to be considered preferable to the array version.

    Regards
    Could you elaborate on those reasons?

    Thanks.

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: [Solved] Assigned value to cell based on two references

    I personally don't have time right now, unfortunately, though you may find this link of interest:

    http://www.decisionmodels.com/optspeedj.htm

    Regards

+ 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. Search for a cell value based on 2 references
    By IN_FOR_SIN in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-07-2013, 09:05 AM
  2. Replies: 2
    Last Post: 07-24-2012, 11:47 AM
  3. Cell value based on three references cells
    By ChrisNor in forum Excel General
    Replies: 4
    Last Post: 04-17-2009, 07:26 AM
  4. return cell references based on criteria
    By blakeyoung in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-22-2008, 09:10 PM
  5. Changing File references based on cell value
    By CParnell in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-29-2007, 12:55 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