+ Reply to Thread
Results 1 to 4 of 4

How to select, copy and paste rows from a find operation

  1. #1
    Registered User
    Join Date
    04-27-2013
    Location
    Limpopo, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    2

    Lightbulb How to select, copy and paste rows from a find operation

    I have the following code that finds the string in the following VBA code. The problems is I have to re-enter the search string every time the macro runs. How can I adjust this code to select, copy and paste (as it does for the first string it finds) all the remaining rows relevant to the this search string?

    Dim lngNextRow As Long
    Dim strMyString As String
    Sheets("ww1186").Activate

    strMyString = InputBox("Enter the number you wish to find")

    On Error GoTo err_Trap


    Cells.Find(What:=strMyString, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext).Activate

    ActiveCell.EntireRow.Copy

    Sheets("Sheet1").Select
    lngNextRow = Range("A" & rows.Count).End(xlUp).Row + 1
    Range("A" & lngNextRow).PasteSpecial


    err_Trap:
    If Err.Number = 91 Then
    MsgBox "Could not find " & strMyString & " anywhere on this sheet.", , "Unsuccessful search"


    Can someone please help?
    Many thanks
    Lambert

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: How to select, copy and paste rows from a find operation

    You will probably have to use "For Next" for this one.

    Can you attach a Sample Workbook?


    Thank You,

    Deep
    Last edited by NeedForExcel; 04-27-2013 at 07:36 AM.
    Cheers!
    Deep Dave

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to select, copy and paste rows from a find operation

    Hi, Lambert,

    could you please wrap the code with Code-Tags?

    Please try if this is what you are looking for
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    04-27-2013
    Location
    Limpopo, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: How to select, copy and paste rows from a find operation

    Hi Holger,

    Wow!!! this code really works very well indeed. Thanks a million. I have learnt a valuable lesson in how to loop with the boolean type of variable. I would not dreamed of using a boolean this way. Yes, guilty as charged...the comments about "Code Tags". I'll get this sorted right away.

    thanks again

    Lambert

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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