+ Reply to Thread
Results 1 to 9 of 9

display matching data in new column

  1. #1
    Forum Contributor
    Join Date
    10-02-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    165

    display matching data in new column

    Hi,

    In the attached sheet, I have two sub sheets "Inform" and "Company".

    My requirement is to develop one macro to insert two new columns (Teams, Statuscheck) in sheet "Inform" after first column i.e. "Name".

    For those inserted new columns, I want to populate the data from sheet "Company" if user names are matching between two sheets ( Inform.Name=Company.C_Name)

    Thanks in advance for your help
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: display matching data in new column

    Please Login or Register  to view this content.
    Last edited by walruseggman; 02-02-2016 at 11:38 AM.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: display matching data in new column

    Walrus,

    You came up with a solution much quicker than I could! I'm still learning...

    On that note, does this line: For Each c In Range("A2:A" & ws1.Cells(Rows.Count, 1).End(3).Row) loop over ALL rows in the entire worksheet, regardless of whether or not there is content in the cells or is excel smart enough to only loop over the current region? I thought Rows.Count with no reference to a range will return all rows in the worksheet but I could be wrong.

    Thanks in advance if you have time to comment on your solution.
    <---If my answer helped, please click *

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: display matching data in new column

    Please Login or Register  to view this content.
    Will return the row number of the last row in column 1 with a value in it. So, in theory, if there were a couple blank cells in column 1, and then a continuation of cells with values afterwards, the code would still run on those blank cells.

    Not usually a big deal, especially if the data set is small, or as in this case, the OP provides a sample that shows no blank cells.

    However, if time is a crucial factor, or there are a ton of blank cells in your data set that you don't want the code to waste it's time on, one very easy solution is to use SpecialCells. For example, this would run on only the cells in column 1 (minus cell A1) that have text values in them, and would ignore any blank cells, cells with formulas, cells with numbers in them, etc.:

    Please Login or Register  to view this content.
    Hope that helps.

  5. #5
    Forum Contributor
    Join Date
    10-02-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    165

    Re: display matching data in new column

    Thank you very much for your great support.

    The user contain some extra space for which the column is not populated (e.g. for user 'Rakesh mehra' in row number 4, the team column is blank where as the same populated in rownum 2).
    Could you guide where the trim function should be used.

  6. #6
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: display matching data in new column

    Sara,

    The reason "Rakesh mehra" was not found on the "Inform" worksheet was probably because the search method used distinguished between "Rakesh mehra" and "Rakesh Mehra". I noticed there were some trailing and leading spaces that can also cause some issues, depending on how the solution is coded. The following code is robust enough to handle trailing and leading spaces in addition to capitalization errors. Any other mistakes such as misspellings, forgetting the ".", or two spaces between the first and last name will result in the Find method used in the code below to miss the name on the "Inform" worksheet.

    If a name is not found, I displayed a Message box specifying which name was not found. You can comment that line out if you don't want the message box.

    I debugged and tested the following code on your test worksheet. Let me know if there are any problems.

    Please Login or Register  to view this content.
    Last edited by joe31623; 02-03-2016 at 02:49 AM.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: display matching data in new column

    You may also try something like this.....

    Please Login or Register  to view this content.
    In the attached, click the button on Inform Sheet to run the code and see if this is what you were trying to achieve.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  8. #8
    Forum Contributor
    Join Date
    10-02-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    165

    Re: display matching data in new column

    Thank you very much for your kind support.

  9. #9
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: display matching data in new column

    To handle trailing and leading spaces, as well as capitalization:

    Please Login or Register  to view this content.

+ 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. Display last 6 month's worth of data matching a specific criteria
    By pun2013 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-11-2014, 03:10 PM
  2. Finding Matching Data in one Column/Adding corresponding matching string value.
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2013, 07:23 PM
  3. DIsplay data in sheet2 if ID are matching with sheet1
    By abraham30 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2013, 02:13 AM
  4. Replies: 1
    Last Post: 04-23-2013, 12:46 AM
  5. Replies: 9
    Last Post: 07-22-2012, 12:03 PM
  6. Matching Data in a Row and Display in Column
    By grizzly1733 in forum Excel General
    Replies: 3
    Last Post: 04-01-2006, 05:42 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