+ Reply to Thread
Results 1 to 17 of 17

Search workbook for matching detail and copy/paste the row/column content.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Search workbook for matching detail and copy/paste the row/column content.

    Hi all

    My first post, I am attempting to create a macro in Excel 2003 and unfortunately am struggling to get to grips with it. What I am looking to get running is a macro for the following:

    My workbook has:
    One sheet with name and staff numbers on only (Called Track)
    Several other sheets (called Course 09 , Course 11 etc) with several columns of info, including name and staff numbers.

    What I would like to be able to do is for a macro to look at the staff numbers on the sheet Track, then look through all the Course sheets and where it finds a match copy the contents of the matching row’s column C from Course into the matching row’s column C from Track.

    Alternatively and probably simpler if it finds a match just add Found or Not Found into the matching row’s column C from Track.

    Any help would be greatly appreciated.
    Last edited by GB.RTMC; 11-28-2012 at 04:04 AM.

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Hi,

    Welcome the World of Excel Forum and enjoy .

    Please provide the sample workbook its easy to solve.

    Thanks - Naveed

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Hopefully a very basic sample file should be attached. Thanks for any help.
    Attached Files Attached Files
    Last edited by GB.RTMC; 11-27-2012 at 10:42 AM.

  4. #4
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Bump - any additional information required, please ask.

  5. #5
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Hi,

    I want to know one thing is that course tabs will increase day by day or else that three tabs only.

  6. #6
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Naveed Raza - There will be one or two extra tab added during a year only.

  7. #7
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Search workbook for matching detail and copy/paste the row/column content.

    so total max to max how many tabs will there so that i can update the formula only macro will not required

  8. #8
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    There will never be more than 6 tabs, though the number of rows compared with the sample sheet will be higher. There could be as many as 700 rows on a tab.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search workbook for matching detail and copy/paste the row/column content.

    GB,
    See if this gives you a good start.
    Please note that I have also highlighted the common cells in both track and other sheets. Let me know if you wish to remove them

    Sub find_copy()
    Dim c2 As Range, c As Range
    With Sheets("Track")
        .Range("C2:C" & .Rows.Count - 1).Clear
        For Each c2 In .Range("B2:B" & .Cells(Rows.Count, 1).End(xlUp).Row)
            For Each ws In Worksheets
                If ws.Name Like "Course*#" Then
                Set c = ws.Columns(2).Find(c2, , xlValues, xlWhole)
                    If Not c Is Nothing Then
                     c.EntireRow.Interior.ColorIndex = 3
                     c2.EntireRow.Interior.ColorIndex = 3
                    c.Offset(, 1).Copy Sheets("Track").Range("C" & Rows.Count).End(xlUp).Offset(1)
                    End If
            End If
            Next ws
       Next c2
     End With
    End Sub

  10. #10
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Hi,

    I have updated the formula in Track Tab.

    Please have review and let me know if u hv any question/queries

    Thanks - Naveed
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Naveed Raza - Unfortunately the version of Excel I am using at work only allows a max of seven levels of nesting in a forumla, so it is not able to open the formula. But thank you very much for your assiatnce.

    AB33 - That looks like it fits exactly what i need it to do, though highlighting the fields is something that wouldn't work (I hadn't mentioned that cells are colour coded on the sheets separately to represent something else, so I will need to remove that one option). Thankyou very much for your help

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search workbook for matching detail and copy/paste the row/column content.

    I am glad to know it has worked for you!

  13. #13
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    I have just noticed one problem that I may have. Where someone appears on the Track sheet but does not appear on a Course sheet it would mean that the copy and pasted information would not be in the same row afterwards.

    Is there an easy way to add to the macro that where someone appears on the Track sheet but is not found on the Course sheets to output to the relevant column/row "Not Found" so that the information found on people below that name have their data in the same row?

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search workbook for matching detail and copy/paste the row/column content.

    GB,
    I was aware the fact that the rows found in each sheet do not match with the row numbers in the Trackt sheet. I am still trying to get around the problem. The code copies when it finds match in to the next empty cells in track column C, instead of aliening with the row number. In the mean time, I have added a new line, and see if this helps.

    Sub find_copy()
    Dim c2 As Range, c As Range
    With Sheets("Track")
        .Range("C2:C" & .Rows.Count - 1).Clear
        For Each c2 In .Range("B2:B" & .Cells(Rows.Count, 1).End(xlUp).Row)
            For Each ws In Worksheets
                If ws.Name Like "Course*#" Then
                Set c = ws.Columns(2).Find(c2, , xlValues, xlWhole)
                    If Not c Is Nothing Then
                     c.Offset(, 3) = "Found"
                     c2.Offset(, 3) = "Found"
                    c.Offset(, 1).Copy Sheets("Track").Range("C" & Rows.Count).End(xlUp).Offset(1)
                    End If
            End If
            Next ws
       Next c2
     End With
    End Sub

  15. #15
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Need to change this line. See if this helps. Problem is your looking up column C to get the next row. Just use you Var c2.address witch is Column b then offset 1 column

    c.Offset(, 1).Copy Sheets("Track").Range("C" & Rows.Count).End(xlUp).Offset(1)
    to
    c.Offset(, 1).Copy Sheets("Track").Range(c2.Address).Offset(, 1)
    Last edited by mike7952; 11-28-2012 at 09:35 AM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  16. #16
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search workbook for matching detail and copy/paste the row/column content.

    Mike!
    It does indeed! Thanks again for your timely intervention.

    Now the found rows match with the copied match on the track sheet. I hope this will satisfay the OP.

    Sub find_copy()
    Dim c2 As Range, c As Range
    With Sheets("Track")
        .Range("C2:E" & .Rows.Count - 1).Clear
        For Each c2 In .Range("B2:B" & .Cells(Rows.Count, 1).End(xlUp).Row)
            For Each ws In Worksheets
                If ws.Name Like "Course*#" Then
                Set c = ws.Columns(2).Find(c2, , xlValues, xlWhole)
                    If Not c Is Nothing Then
                     c.Offset(, 3) = "Found"
                     c2.Offset(, 3) = "Found"
                    c.Offset(, 1).Copy Sheets("Track").Range(c2.Address).Offset(, 1)
                    End If
            End If
            Next ws
       Next c2
     End With
    End Sub

  17. #17
    Registered User
    Join Date
    11-27-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Search workbook for matching detail and copy/paste the row/column content.

    AB33 I ran that on my test document, first look it ran beautifully, looking very hopeful that you and mike7952 have solved my problem. I'll adapt it for my main sheet and see how it runs. Again thank you very much for your time, effort and overall assistance. Much appreciated.

    mike7952 that line looks to solve the problem on my test sheet. Thank you very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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