Excel Search and Copy macro
Closed
ahawk
-
22 Jan 2010 à 14:18
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 23 Jan 2010 à 20:16
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 23 Jan 2010 à 20:16
Related:
- Excel Search and Copy macro
- Spybot search and destroy - Download - Antivirus
- Excel mod apk for pc - Download - Spreadsheets
- Yahoo search history - Guide
- How to copy data from one excel sheet to another - Guide
- Google search from usa - Guide
1 response
venkat1926
Posts
1863
Registration date
Sunday 14 June 2009
Status
Contributor
Last seen
7 August 2021
811
23 Jan 2010 à 20:16
23 Jan 2010 à 20:16
I suppose your data is something like this
gene_code hits
a
s
d
f
g # 1 hits found
h
j
k
l # 1 hits found
m
n
your source sheet is called sheet1 and the destination sheet is called sheet2
It would have been nicer if you had just entered 1, 2, 3 etc in the hits column.But you have put a string # 1 hits found. in that case you have to be very careful in spelling not only in the sheet1 but also in the macro below against the definition of x. Even if there is unnecessary space anywhere will mess up the results.
anyhow try this macro
gene_code hits
a
s
d
f
g # 1 hits found
h
j
k
l # 1 hits found
m
n
your source sheet is called sheet1 and the destination sheet is called sheet2
It would have been nicer if you had just entered 1, 2, 3 etc in the hits column.But you have put a string # 1 hits found. in that case you have to be very careful in spelling not only in the sheet1 but also in the macro below against the definition of x. Even if there is unnecessary space anywhere will mess up the results.
anyhow try this macro
Sub test()
Dim r As Range, cfind As Range, x, add As String
x = "# 1 hits found"
On Error Resume Next
With Worksheets("sheet1")
Set r = Range(.Range("B2"), .Range("B2").End(xlDown))
Set cfind = r.Cells.Find(what:=x, lookat:=xlWhole)
If Not cfind Is Nothing Then
Range(cfind.Offset(-3, 0), cfind.Offset(1, 0)).EntireRow.Copy
add = cfind.Address
With Worksheets("sheet2")
.Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
End With
End If
Do
Set cfind = .Cells.FindNext(cfind)
If cfind Is Nothing Then Exit Do
If cfind.Address = add Then Exit Do
With Worksheets("sheet2")
.Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
End With
Loop
End With
Application.CutCopyMode = False
End Sub