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:
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello and welcome to MrExcel.

Try this with a copy of your workbook.

Code:
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 <> "Bundle" 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("Bundle")
        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
 
Upvote 0
In the instance where I tried it it neither highlighted the correct entry nore did it paste anything onto sheet "bundle"

Slightly confused by this bit, is it referring to the sheet that its pasting to?

Code:
 If ws.Name <> "Bundle" Then
 
Upvote 0
That in effect is saying don't search sheet Bundle for the value.

If you want the found value highlighted:

Rich (BB code):
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 <> "Bundle" 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
    Found.Interior.ColorIndex = 3
    With Sheets("Bundle")
        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

Can you post a small sample of data from one sheet only using http://www.excel-jeanie-html.de/html/hlp_schnell_en.php and indicate an example of data that you want to find. Remove any sensitive information first!
 
Upvote 0
****! I missed a dot

Rich (BB code):
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 <> "Bundle" 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
    Found.Interior.ColorIndex = 3
    With Sheets("Bundle")
        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
 
Upvote 0
Sorry, I haven't used that website before or seen it, I am new to the forums and I am still getting use to things...

Basically when I search (example) for bob in a really long list I want it to find it and then paste that row in the the next emtpy row in the next sheet. I know how to do the search bit and the next row but I can't seem to get the copy and paste to work...
 
Upvote 0
Example:
exampleng9.png

There will be more columns but the idea is it pastes the name and all coloumns into another sheet.
 
Upvote 0
ok I have been messing around with this for ages now, the problem is getting it to copy and past... here is the current code atm but there is a problem, I just don't know what! This is just the last snippet:

Code:
Else
    Found.Interior.ColorIndex = 3
    With Sheets("Sheet1")
        LR = .Range("A" & Rows.Count).Row
        Found.EntireRow.Copy Destination:=.Range("A" & LR + 1).Select
        Sheets("Sheet2").Select
        Range("A1").Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(1, 0).Select
        Selection.Paste
    End With
End If
Application.CutCopyMode = False
End Sub

Sheet1 = This has the database on it
Sheet2 = This is where I want it to paste... The search button is also on this page
 
Upvote 0
So you want to search Sheet1 for a value and paste the row to Sheet2?

Code:
Sub Find_Data()
Dim datatoFind As Variant, Found As Range, LR As Long
datatoFind = InputBox("Please enter the value to search for")
If datatoFind = "" Then Exit Sub
Set Found = Sheets("Sheet1").UsedRange.Find(What:=datatoFind, LookIn:=xlValues, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
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 + 1)
    End With
    Application.CutCopyMode = False
End If
End Sub
 
Upvote 0
Thanks a million... That really has helped... Now there is just a little bits which I have tried but I don't know how to change it...

Change 1: Instead of a input box;
Code:
datatoFind = InputBox("Please enter the value to search for")
Could I change it to; ex.
Code:
datatoFind = range("A1")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,790
Messages
6,174,594
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