Closed Thread
Results 1 to 4 of 4

Code to search for matching values in two columns, take text from that row and copy

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    83

    Code to search for matching values in two columns, take text from that row and copy

    Hello

    To my ability it's a bit complicated.
    However my problem is that I have several hundred sheets which have to do the same procedure.

    I have to search a row with ID's, whenever that number changes, I have to put in a cell above and below when the numbers changes.
    SO for example I have in row C:
    111
    111
    222
    222
    333

    that have to be:

    111
    111
    (new row)
    222
    222
    (new row)
    333

    Then I have to type in a certain text below and above when the value changes.
    I have this code to search and insert a cell:

    Sub InsertRows()
    Dim lastRow As Long
    Dim rowPtr As Long
    
    lastRow = Range("C" & Rows.Count).End(xlUp).Row
    For rowPtr = lastRow To 2 Step -1
    If Not IsEmpty(Range("C" & rowPtr)) Then
    If Range("C" & rowPtr) <> Range("C" & rowPtr - 1) Then
    Range("C" & rowPtr).EntireRow.Insert
    End If
    End If
    Next
    End Sub
    However I have to seach column B
    for matching values.
    so column b will have the same values somewhere I.e:
    111
    111
    222
    222
    333
    I have to find that matching value and copy the text from the corresonding row (in column B) to the inserted in the rows the macro made when the values in column C changes.
    Hope I have made my issue understandable, please tell me if it helps to make some sort of draft to upload or something.

    Appreciate any help or guidance.
    Thanks in advance

    Kind regards
    Last edited by arlu1201; 05-23-2014 at 12:11 PM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Code to search for matching values in two columns, take text from that row and copy

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    03-06-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Code to search for matching values in two columns, take text from that row and copy

    Okay, thanks

    I've just made a little file to hopefully show what is needed.

    things that the code needs to do:
    1. Identify when Column B changes value, then insert two blank rows above and below
    2. Identify matching values in Column B and C (Task_ID and Parent_task) because the same Task_ID and Parent_task is located in different places in the sheets.
    3. insert "Begin" above the cell in the new blank row in Column C where the values changes
    4. Insert "end" below the cell in column C where the value changes
    5. Copy values from column D-F from matching row in column B
    6. Paste matching values from Column D's into the same row as the new "begin" and "end" Rows.

    Don't know if make sense ?

    So main thing is the identify matching values from Parent_task and Task_ID and the insert two blank rows above and below where the values in Parent_task Column (Column C) changes, and copy the cells from matching column C (but only the columns D-F's cells in the same row as the matching value in column B is.
    Attached Files Attached Files

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Code to search for matching values in two columns, take text from that row and copy

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 03-14-2014, 06:46 PM
  2. Compare columns and finding matching values/text
    By debake in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-02-2014, 09:27 AM
  3. Code to search for matching text in a table then copy next line
    By douglasm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-27-2014, 12:10 PM
  4. Replies: 0
    Last Post: 10-07-2013, 10:24 AM
  5. [SOLVED] Search for a value in a column and copy row to new sheet for all matching values
    By mrcois in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2012, 12:09 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