+ Reply to Thread
Results 1 to 3 of 3

Assigning certain data a value based on whole data

  1. #1
    Registered User
    Join Date
    12-30-2013
    Location
    Elgin
    MS-Off Ver
    Excel 2013
    Posts
    52

    Assigning certain data a value based on whole data

    Sorry for confusing title, I don't really know how to describe this.

    Anyhow, I've gotten a lot of help on this site, but I'm still pretty new to coding. I have the ideas I want, but I don't know how to execute them. Hoping to learn more today!

    Uploading my worksheet. Column A and Column B can have varying data and ranges, but will always be the two columns with the data I need to use in it. I would like the output to end up in column C. I gave an example of what a finished project would look like in column D.

    So I want a couple things to happen.

    First - Scan the values in row 1 column A. Look for matching values in all of column B.
    If there is a matching value, print a "1" in the cell next to the matched B value. (Column C). Do this for all matching values in row 1.
    Proceed to the next row. Scan values in A, look for matching values in B.
    If you had matching values in row 1, print a "2" in the cell next to the matched B value.
    If you did not have matching values in row 1, print a "1" in the cell next to the matched B value.

    Repeat this until you have gone through every row in Column A. The next step would have a "3" if both previous rows had matching data. It would continue to count up until you reached the last row.

    Second - Scan all values in column B. For all values that don't have a matching value in column A, print out a "222" in the cell next the B value into column C.

    Finished!

    Sorry if this was confusing. I'll be around for any help and questions.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,062

    Re: Assigning certain data a value based on whole data

    Yep, pretty confusing, at least to me.

    So, in "Row 1 Column A", the value is "Data1". I'm supposed to look for a match for "Data1" in column B? Or, are you talking about Row 2, the first row with data? If so, I look first for A55 in column B, and if I see it, then I put a 1 next to A55 if it exists in column B, then move on to A56, A58, etc?

    "If you had matching values in row 1, print a "2" in the cell next to the matched B value." So replace the 1 we already put with a 2?

    "If you did not have matching values in row 1, print a "1" in the cell next to the matched B value." So everything we didn't find we now put a 1 by, and all the previous 1's have been converted to 2's?

    Finally, I guess we replace all of our 2's with 222? Not sure yet how 3 comes in.

  3. #3
    Registered User
    Join Date
    12-30-2013
    Location
    Elgin
    MS-Off Ver
    Excel 2013
    Posts
    52

    Re: Assigning certain data a value based on whole data

    Quote Originally Posted by jomili View Post
    Yep, pretty confusing, at least to me.

    So, in "Row 1 Column A", the value is "Data1". I'm supposed to look for a match for "Data1" in column B? Or, are you talking about Row 2, the first row with data? If so, I look first for A55 in column B, and if I see it, then I put a 1 next to A55 if it exists in column B, then move on to A56, A58, etc?

    "If you had matching values in row 1, print a "2" in the cell next to the matched B value." So replace the 1 we already put with a 2?

    "If you did not have matching values in row 1, print a "1" in the cell next to the matched B value." So everything we didn't find we now put a 1 by, and all the previous 1's have been converted to 2's?

    Finally, I guess we replace all of our 2's with 222? Not sure yet how 3 comes in.
    Hmmm yep sorry. Let's see if I can clear some of this up.

    First off - You are correct in that you would actually be starting on Row 2. I just added row 1 to give a quick description of each column.

    Any output that this code will create will be put in Column C. Nothing else.

    I'll go over the first few lines. I might not be doing it the most optimal way.

    Scan all values in cell A2. Look for matching values in Column B. If a matching value is found, place (counter variable) 1 next to the match in Column C. If there are no matching value, move to next line and don't change the counting variable.
    Next line.
    Scan all values in cell A3. Look for matching values in Column B. Since matches are found, assign all matches the counting variable in Column C. So "A18", "A19", "A22" etc have "1" next to them in Column C. Now the next row that has matches for values, counting variable will go up 1. This repeats every time you find matches. If there are no matches, variable stays at the last number used.
    Next line.
    Scan all values in cell A4. Matches are found in Column B. ("A78", "A79"). Now we assign counting variable 2 next to the matches in Column C.
    Next line. Do the same thing, if you have matches, assign counting variable 3, if there are no matches, go to the next line. You will repeat this until there are no values in the next row of column A. In this case that happens at row 45.

    Once you finish scanning every line in the first step, theoretically all the values in column B will have a counting variable next to it in column C. If they don't have a counting variable next to it, then I want to have 222 placed next to it. I figured this could be accomplished by finding which values don't have a match by scanning all of Column B.

    Column D in my sheet is what the actual end result is. I went and did that one manually as an "answer sheet."

    Hope that clears it up even a little bit.
    Last edited by Jveto; 10-11-2016 at 04:58 PM.

+ 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. Assigning data dynamically
    By JohnTopley in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-30-2021, 10:46 AM
  2. Assigning data dynamically
    By JohnTopley in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-15-2015, 02:35 PM
  3. [SOLVED] Counting specific data and extracting that data by rearranging by assigning numbering
    By paradise2sr in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-25-2014, 07:11 AM
  4. Assigning Values from Fixed Data Set to Variable Data Set
    By Jaricketts in forum Excel General
    Replies: 4
    Last Post: 04-21-2010, 01:24 PM
  5. Automatically assigning data series
    By driffert in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-11-2008, 09:24 AM
  6. Assigning Multiple Rankings to Data based on different columns
    By Mike610 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-23-2008, 07:43 PM
  7. Replies: 2
    Last Post: 11-20-2007, 04:47 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