Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
copy rows from one Data sheet to another sheet based on cell conte | Excel Discussion (Misc queries) | |||
Copy an excel sheet from one file to another including formulas | Excel Discussion (Misc queries) | |||
How do I copy a range in Excel without including hidden rows? | Excel Discussion (Misc queries) | |||
Search for rows in one sheet and copy into another sheet based on customer id | Excel Worksheet Functions | |||
Pivot Tables: How do I show ALL field rows, including empty rows?? | Excel Worksheet Functions |