Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default copy rows that contain certain text to a new sheet including the h

hello,

i am writing a macro to copy rows which contain certain words.
i am using a macro which i used before to highlight the rows where the word
appears.
but i'm not sure about the code i should use now.
i welcome your comments
mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default copy rows that contain certain text to a new sheet including the h

Hi Mike,

Try something like:

'==========
Public Sub Tester()
Dim rng As Range
Dim rCell As Range
Dim copyRng As Range
Dim destRng As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim CalcMode As Long
Dim arr As Variant

Set WB = ActiveWorkbook '<<=== CHANGE
Set SH = WB.Sheets("Sheet1") '<<=== CHANGE
Set rng = SH.Range("A1:A100") '<<=== CHANGE
Set destRng = WB.Sheets("Sheet2").Range("A2") '<<=== CHANGE

arr = Array("Anne", "Jon", "Kate") '<<===
CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In rng.Cells
If Not IsError(Application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<==========


---
Regards,
Norman


"mike" wrote in message
...
hello,

i am writing a macro to copy rows which contain certain words.
i am using a macro which i used before to highlight the rows where the
word
appears.
but i'm not sure about the code i should use now.
i welcome your comments
mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default copy rows that contain certain text to a new sheet including the h

Norman,
Thanks for that, its along the lines of what i want.
But,
I want to include an input box, so basically heres what happens:
run the macro
input box - enter bob dave or fred
search column c, cells 4 to 100,
copy the row from column a to l where bob lies to sheet 2

any more suggestions
thanks

mike

"mike" wrote:

hello,

i am writing a macro to copy rows which contain certain words.
i am using a macro which i used before to highlight the rows where the word
appears.
but i'm not sure about the code i should use now.
i welcome your comments
mike

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default copy rows that contain certain text to a new sheet including the h

Hi Mike

Try EasyFilter for this
http://www.rondebruin.nl/easyfilter.htm

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


"mike" wrote in message ...
Norman,
Thanks for that, its along the lines of what i want.
But,
I want to include an input box, so basically heres what happens:
run the macro
input box - enter bob dave or fred
search column c, cells 4 to 100,
copy the row from column a to l where bob lies to sheet 2

any more suggestions
thanks

mike

"mike" wrote:

hello,

i am writing a macro to copy rows which contain certain words.
i am using a macro which i used before to highlight the rows where the word
appears.
but i'm not sure about the code i should use now.
i welcome your comments
mike



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default copy rows that contain certain text to a new sheet including the h

Hi Mike,

Go with Ron's suggestion or try this adaptationn of the suggested code:

'==========
Public Sub Tester()
Dim Rng As Range
Dim rCell As Range
Dim copyRng As Range
Dim destRng As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant

Set WB = ActiveWorkbook '<<=== CHANGE
Set SH = WB.Sheets("Sheet1") '<<=== CHANGE
Set Rng = SH.Range("C4:C100")
Set destRng = WB.Sheets("Sheet2").Range("A2") '<<=== CHANGE

res = InputBox("Enter search words separated with a space")

If res = "" Then Exit Sub
arr = Split(res, " ")

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In Rng.Cells
If Not IsError(Application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<==========

--

---
Regards,
Norman



"mike" wrote in message
...
Norman,
Thanks for that, its along the lines of what i want.
But,
I want to include an input box, so basically heres what happens:
run the macro
input box - enter bob dave or fred
search column c, cells 4 to 100,
copy the row from column a to l where bob lies to sheet 2

any more suggestions
thanks

mike

"mike" wrote:

hello,

i am writing a macro to copy rows which contain certain words.
i am using a macro which i used before to highlight the rows where the
word
appears.
but i'm not sure about the code i should use now.
i welcome your comments
mike





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
copy rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
Copy an excel sheet from one file to another including formulas Nicolas Heyer Excel Discussion (Misc queries) 4 July 22nd 09 10:36 AM
How do I copy a range in Excel without including hidden rows? Lang Excel Discussion (Misc queries) 1 February 22nd 08 02:48 PM
Search for rows in one sheet and copy into another sheet based on customer id [email protected] Excel Worksheet Functions 1 October 22nd 07 03:09 AM
Pivot Tables: How do I show ALL field rows, including empty rows?? [email protected] Excel Worksheet Functions 2 April 8th 05 06:21 PM


All times are GMT +1. The time now is 09:52 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"