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.
Bookmarks