Consulting

Results 1 to 13 of 13

Thread: VBA findAll Copy & Paste

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    VBA findAll Copy & Paste

    On a Userform, How do I structure a search so that it finds all the values in a selected row that matches the criteria entered in a textbox and a ComboBox, and copies them to another sheet.

    Attached are the worksheets & a more detailed explaination.

    Thanks

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    This should give you and idea on how to achieve it, there is a worked example of choosing a name (click the button and type either a month in this fashion Jan or a day like this Mon), selecting all occurences and displaying them in a textbox, the cell addresses are then clickable, you should be able to manipulate this to suit.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Simon Thanks:

    I'll need to re-think the way I was looping.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this. It is coded for Account Number search only. Both books must be open.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Hi:

    Still having a problem getting the code to get the first value in the range as the first selected value. My code is a modification of this http://www.cpearson.com/excel/FindAll.aspx

    Any idea why Its selecting the first value in the Range as the last found cell?

    [VBA]
    With Sheets("Sheet1").Range("D3:P3")
    ' Set col = Range("D3:P3")
    Set LastCell = .Cells(.Cells.count)
    End With
    Set FoundCell = Range("D3:P3").Find(what:=ComboBox1.Value, after:=LastCell)

    If Not FoundCell Is Nothing Then
    FirstAddr = FoundCell.Address
    End If
    Do Until FoundCell Is Nothing
    Debug.Print FoundCell.Address
    Set FoundCell = Range("D3:P3").FindNext(after:=FoundCell)

    With FoundCell
    rsCol = FoundCell.Column

    End With

    Cells(rsRow, rsCol).Select
    MsgBox ActiveCell.Address & " " & " Cell Amount is " & " " & ActiveCell.Value

    If FoundCell.Address = FirstAddr Then
    Exit Do
    End If
    Loop
    [/VBA]


    Suggestions & ideas welcome

    Thanks

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You are looking after the first found cell in your loop. Check FindNext in Help for correct looping syntax.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Sorry:

    Same worksheet as provided earlier;
    Attached are the worksheets & a more detailed explaination.

    Thanks
    Attached FilesVB-Sheets.zip

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Is Post 4 not giving the correct result? If not, can you please show the correct result in Postings.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    mdmackillop :

    I dont get it. Did the help search etc..etc.. I tried every variation and I'm still either finding the 3rd value first, or the 2nd value.

    How can I fix this?

  10. #10
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    mdmackillop :
    Post 4 did give the correct results, however, I'm trying to understand the code that I presented as I'm using the process for multiple operations. I did not see you post for some reason, but understanding is part of the learning process. How can I fix this? I really appreciated your help.

  11. #11
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks GTO
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by mdmackillop
    Thanks GTO
    You bet Malcom

Posting Permissions

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