+ Reply to Thread
Results 1 to 5 of 5

copy rows that contain certain text to a new sheet including the h

Hybrid View

Guest copy rows that contain... 12-05-2005, 09:35 AM
Guest Re: copy rows that contain... 12-05-2005, 09:55 AM
Guest RE: copy rows that contain... 12-05-2005, 10:15 AM
Guest Re: copy rows that contain... 12-05-2005, 10:25 AM
Guest Re: copy rows that contain... 12-05-2005, 10:35 AM
  1. #1
    mike
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <mike@discussions.microsoft.com> wrote in message
    news:006C6787-73C2-420E-A56C-F366BCF5E243@microsoft.com...
    > 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. #3
    mike
    Guest

    RE: 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. #4
    Ron de Bruin
    Guest

    Re: 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" <mike@discussions.microsoft.com> wrote in message news:4781C39A-D359-4B82-A461-33E3A96DB3C3@microsoft.com...
    > 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. #5
    Norman Jones
    Guest

    Re: 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" <mike@discussions.microsoft.com> wrote in message
    news:4781C39A-D359-4B82-A461-33E3A96DB3C3@microsoft.com...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1