Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


I need a macro that will search for all occurances of the word "tool" in
col B of a spreadsheet and then copy the entire row of each occurance
and paste the rows in another worksheet within the same spreadsheet


--
TonyG001
------------------------------------------------------------------------
TonyG001's Profile: http://www.excelforum.com/member.php...o&userid=35737
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Find and copy in Excel

Try this friend....
I know you can use advancedfilter too, but this is a quick and dirty
one...

Sub CopyRowsBasedOnCellContents()
Dim SourceTab As String
Dim DestTab As String
Dim DestRow As Integer
Dim SearchText As String

'TURN SCREEN UPDATED ON TO KEEP YOU
'FROM SWOLLOWING YOUR TOUNG IF YOU
'HAVE A BUNCH OF ROWS.
Application.ScreenUpdating = False


SourceTab = "Sheet1"
DestTab = "Sheet2"
SearchText = "Tool"

For x = 1 To 99 'YOU'LL NEED TO EDIT THIS TO ACCOUNT FOR THE ROWS
YOUR READING

If InStr(UCase(Sheets(SourceTab).Cells(x, "B")),
UCase(SearchText)) < 0 And Trim(Sheets(SourceTab).Cells(x, "B")) < ""
Then
Sheets(SourceTab).Rows(x & ":" & x).Copy
Sheets(DestTab).Select
Sheets(DestTab).Range("B1").Select

If Trim(Sheets(DestTab).Range("B1").Value) < "" Then
DestRow = Sheets(DestTab).Range("B1").End(xlDown).Row +
1
Sheets(DestTab).Rows(DestRow & ":" & DestRow).Select
End If

ActiveSheet.Paste
Sheets(SourceTab).Select

End If

Next x

Application.ScreenUpdating = True
End Sub

Regards,
Jamie





TonyG001 wrote:
I need a macro that will search for all occurances of the word "tool" in
col B of a spreadsheet and then copy the entire row of each occurance
and paste the rows in another worksheet within the same spreadsheet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


Or try this

Sub FindTool()
Dim myRange As Range
Set myRange = Range("B:B")
For Each Cell In myRange
If UCase(Cell.Value) = "TOOL" Then
Cell.EntireRow.Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveCell.SpecialCells(xlLastCell).Select
Selection.End(xlUp).Offset(1, 0).Select
Selection.EntireRow.Select
ActiveSheet.Paste
Sheets("Sheet1").Select
Application.CutCopyMode = False
End If
Next Cell
End Sub


--
Mallycat
------------------------------------------------------------------------
Mallycat's Profile: http://www.excelforum.com/member.php...o&userid=35514
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


thanks Jamie but the macro is stopping at
If InStr(UCase(Sheets(SourceTab).Cells(x, "B")),

any suggestions?


--
TonyG001
------------------------------------------------------------------------
TonyG001's Profile: http://www.excelforum.com/member.php...o&userid=35737
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Find and copy in Excel

It should work. Just make sure you have the whole line on there right
(pasting code on here sometimes breaks the lines at weird spaces. That
entire line ends with the "then".

I've never seen anyone unable to run the instr or ucase functions.

Did you rename the variables to match your workbook? i.e "sourcetab"
and "desttab" etc.
TonyG001 wrote:
thanks Jamie but the macro is stopping at
If InStr(UCase(Sheets(SourceTab).Cells(x, "B")),

any suggestions?


--
TonyG001
------------------------------------------------------------------------
TonyG001's Profile: http://www.excelforum.com/member.php...o&userid=35737
View this thread: http://www.excelforum.com/showthread...hreadid=555185




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


you can also try the Find method (maybe faster)

Sub SearchAndCopy()

Dim varFind

Dim lngFoundRow As Long
Dim lngFirstRow As Long

Dim lngA As Long

Dim strSearch As String
Dim rngA As Range

strSearch = "TOOL"
lngA = Worksheets("destination").Cells(1, 1).CurrentRegion.Rows.Count +
1

With Worksheets("source")
Set varFind = .Columns(2).Find(strSearch, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not varFind Is Nothing Then
lngFirstRow = varFind.Row
Do
For Each rngA In .Rows(varFind.Row).Cells
Worksheets("destination").Cells(lngA,
rngA.Column).Value = .Cells(varFind.Row, rngA.Column).Value
Next rngA
Set varFind = .Columns(2).FindNext(varFind)
lngFoundRow = varFind.Row
lngA = lngA + 1
Loop While Not varFind Is Nothing And lngFoundRow <
lngFirstRow
End If
End With

End Sub

Kind regards,

hugo de wilde


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


Thanks Hugo. Your code worked fine for me I also added two lines that
will first clear the sheet before pasting


--
TonyG001
------------------------------------------------------------------------
TonyG001's Profile: http://www.excelforum.com/member.php...o&userid=35737
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


Hi Millycat

I tried your code and it does not stop but it seems that nothing is
being pasted in my destination sheet.


--
TonyG001
------------------------------------------------------------------------
TonyG001's Profile: http://www.excelforum.com/member.php...o&userid=35737
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and copy in Excel


Yep, try mine:)


--
Mallycat
------------------------------------------------------------------------
Mallycat's Profile: http://www.excelforum.com/member.php...o&userid=35514
View this thread: http://www.excelforum.com/showthread...hreadid=555185

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Find and copy in Excel

See
http://www.rondebruin.nl/copy5.htm


--
Regards Ron De Bruin
http://www.rondebruin.nl



"TonyG001" wrote in message
...

I need a macro that will search for all occurances of the word "tool" in
col B of a spreadsheet and then copy the entire row of each occurance
and paste the rows in another worksheet within the same spreadsheet


--
TonyG001
------------------------------------------------------------------------
TonyG001's Profile: http://www.excelforum.com/member.php...o&userid=35737
View this thread: http://www.excelforum.com/showthread...hreadid=555185





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do we copy all the find cells with their rows in the excel? Siddu Excel Discussion (Misc queries) 1 January 18th 08 09:10 AM
Can Excel Find and Copy a row of data? Still Learning Excel Worksheet Functions 0 September 20th 05 10:06 PM
Excel find text and copy rows Denys-mark Excel Discussion (Misc queries) 2 July 25th 05 11:57 AM
How to generate a file copy of the Excel Find results list MrSpreadsheet Excel Programming 4 February 11th 05 07:07 AM
why can't excel do a simple find and copy row from a worksheet to. rasman Excel Worksheet Functions 2 December 28th 04 05:49 PM


All times are GMT +1. The time now is 03:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"