I need help Copying a row that is returned by a search to another sheet...

Mr Clickalot

New Member
Joined
Feb 7, 2009
Messages
37
Below is the current macro that I have, This searches the whole sheet for key words. It is ideal in the fact that it does not have to be exact. When it finds the entry it simply selects it but heres the problem;

Instead of just highlighting the cell I would like it to copy that row to the next sheet (in my case thats called "Bundle")...

Code:
Sub Find_Data()
Dim datatoFind
Dim sheetCount As Integer
Dim counter As Integer
Dim currentSheet As Integer
On Error Resume Next
currentSheet = ActiveSheet.Index
datatoFind = InputBox("Please enter the value to search for")
If datatoFind = "" Then Exit Sub
sheetCount = ActiveWorkbook.Sheets.Count
For counter = 1 To sheetCount
Sheets(counter).Activate
If IsError(Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate) = False Then Exit For
Next counter
If ActiveCell.Value <> datatoFind Then
Sheets(currentSheet).Activate
End If
End Sub

Please give suggestions, If you have a better search macro for excel that searches key words and pastes I will be happy to give it a try! :confused:
 
Try this

Rich (BB code):
Sub Find_Data()
Dim datatoFind As Variant, Found As Range, LR As Long
With Sheets("Sheet1")
    datatoFind = .Range("A1").Value
    If datatoFind = "" Then Exit Sub
    Set Found = .UsedRange.Find(What:=datatoFind, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
End With
If Found Is Nothing Then
    MsgBox "Not found", vbExclamation
    Exit Sub
Else
    Found.Interior.ColorIndex = 3
    With Sheets("Sheet2")
        LR = .Range("A" & Rows.Count).End(xlUp).Row
        Found.EntireRow.Copy Destination:=.Range("A" & LR + 2)
    End With
    Application.CutCopyMode = False
End If
End Sub
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,
I have been searching high and low for a code that would do pretty much what your first suggestion did, thanks !

Could anyone help me adjust it so that instead of just finding the first instance of the search criteria it finds all rows with relevant data and pastes them ?

Code currently using

Sub Find_Data()
Dim datatoFind As Variant, Found As Range, ws As Worksheet, LR As Long
datatoFind = InputBox("Please enter the value to search for")
If datatoFind = "" Then Exit Sub
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Search" Then
Set Found = ws.UsedRange.Find(What:=datatoFind, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not Found Is Nothing Then Exit For
End If
Next ws
If Found Is Nothing Then
MsgBox "Not found", vbExclamation
Exit Sub
Else
With Sheets("Search")
LR = Range("A" & Rows.Count).End(xlUp).Row
Found.EntireRow.Copy Destination:=.Range("A" & LR + 1)
End With
End If
Application.CutCopyMode = False
End Sub


Thanks :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,791
Messages
6,174,605
Members
452,574
Latest member
hang_and_bang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top