+ Reply to Thread
Results 1 to 4 of 4

Search columns in specific sheets and paste values on sheet1

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    59

    Search columns in specific sheets and paste values on sheet1

    Good morning folks,
    I need your help altering a macro. I've been trying to make some changes for the past couple of days, but I haven't had any luck.
    Currently, a user inputs a search value in cell C4 & presses on the 'search' button. The macro looks throughout all the sheets, except sheet1 and sheet2, and when it finds the value(s), it pastes the corresponding rows on sheet1. Please see attachment.
    What I want it to do is instead of pasting values from all columns, I want it to paste values from specific columns- Column A, H, M, N, O, Q for e.g. And I also want it to paste only the values. Is that possible?

    This is my code:

    Sub MatchingRows()
    Dim Findme As String, ms As Worksheet, ws As Worksheet, rfind As Range, sAddr As Range, Copyrng As Range, r As Long
    
     Application.ScreenUpdating = False
        Set ms = Sheets("Sheet1")
        With ms
            Findme = .Range("C4")
            If Findme = "" Then Exit Sub
            .Rows("8:" & Rows.Count).ClearContents
        End With
    
        On Error Resume Next
        For Each ws In ActiveWorkbook.Sheets
            If Not ws.Name = "Sheet1" And Not ws.Name = "Sheet2" Then
                With ws.Columns("A:Q")
                    Set rfind = .Find(Findme, LookIn:=xlValues, LookAt:=xlWhole)
                    If Not rfind Is Nothing Then
                        Set sAddr = rfind
                        Set Copyrng = ws.Range("A" & rfind.Row).Resize(, 21)
                        Do
                            ms.Range("A14" & Rows.Count).End(xlUp).Offset(1) = ws.Name
                            Set Copyrng = Union(ws.Range("A" & rfind.Row).Resize(, 21), Copyrng)
                            Set rfind = .FindNext(rfind)
                        Loop Until rfind.Address = sAddr.Address
                        Set rfind = Nothing
                        Set sAddr = Nothing
                        If Not Copyrng Is Nothing Then
                            Copyrng.Copy ms.Range("A" & Rows.Count).End(xlUp).Offset(1)
                            Set Copyrng = Nothing
                        End If
                    End If
                End With
            End If
        Next ws
    'Columns.AutoFit
    
    Cells.Select
        With Selection
            .HorizontalAlignment = xlCenter
            .WrapText = False
    End With
    
    Range("A14").Select
        Application.ScreenUpdating = True
    End Sub
    Thank you.
    Attached Files Attached Files

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

    Re: Search columns in specific sheets and paste values on sheet1

    Try the attached.
    Attached Files Attached Files

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

    Re: Search columns in specific sheets and paste values on sheet1

    Another shorter version.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-30-2012
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Search columns in specific sheets and paste values on sheet1

    Both of them work flawlessly. Thanks for your help AB33.

+ 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. Replies: 4
    Last Post: 10-28-2013, 10:57 AM
  2. paste values for specific columns in second to last row
    By meghanalissa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-25-2013, 05:13 PM
  3. Copy data under specific columns in sheet1 n paste to sheet2 under the same headers
    By ShyamEXcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-08-2012, 02:15 PM
  4. delect values in Sheet1 and copy values from Sheet2 and then paste in Sheet1
    By drpramanik in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-02-2011, 05:28 AM
  5. Cut & paste values in range to specific sheets
    By Samba1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2010, 08:55 PM

Tags for this Thread

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