+ Reply to Thread
Results 1 to 11 of 11

Find, copy, and paste marco

  1. #1
    Registered User
    Join Date
    06-08-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2007
    Posts
    20

    Find, copy, and paste marco

    I'm trying to make an ELO calculator, but I don't know much about macros (other than the recording feature).

    How can I take the contents from cell A4 (on sheet 1), search for it (exact search) on sheet 2, copy the contents of the cell 2 columns over of the search result, and paste those results in cell B2 (on sheet 1)?

    When I try doing a record action for the macro, it doesn't copy the search result cell as such but just that cell (so if the result is A13 when I'm recording, it will always do A13, regardless of what search results it gets).

    Any help would be greatly appreciated.
    Last edited by OreEle; 07-29-2011 at 05:56 PM. Reason: Solved

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Find, copy, and paste marco

    Hi OreEle, the following code finds the value from Sheets 1 A4, gathers the data from two columns over from the found cell, and then places it into sheets 1 B2, just as you asked. Let me know if you need more.
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    06-08-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Find, copy, and paste marco

    Thank you very much. It worked perfectly!

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Find, copy, and paste marco

    You are welcome!

  5. #5
    Registered User
    Join Date
    06-08-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Find, copy, and paste marco

    Is there a way to make exact searches? Some of the search names may be "Dan" while there will be "Danny"s and "Danielle"s in there that are sometime confusing the search feature.

    Thank you.

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Find, copy, and paste marco

    Hi OreEle, as I said in my PM to you, you should start a new thread if the question is different, even if the project is the same.

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Find, copy, and paste marco

    Sorry OreEle, I guess your question still fits. For an answer, I don't know! I know that I have had issues with Excel's Find method giving results that were wrong because of the issues you point out (Dan, Daniel, etc). I will post this question to the gurus of this site and hopefully you get an answer soon.

  8. #8
    Registered User
    Join Date
    06-08-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Find, copy, and paste marco

    Quote Originally Posted by Mordred View Post
    Sorry OreEle, I guess your question still fits. For an answer, I don't know! I know that I have had issues with Excel's Find method giving results that were wrong because of the issues you point out (Dan, Daniel, etc). I will post this question to the gurus of this site and hopefully you get an answer soon.
    I was originally thinking that the names could be put in order, so "Dan" would appear before "Daniel" and so when searching for "Dan" it would catch the right one first. However, this needs to accomidate internet forum user names, meaning we'll have some "1_dan_1" that would catch the search first.

  9. #9
    Registered User
    Join Date
    06-08-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Find, copy, and paste marco

    Got it figured out. Just had to hit "ctrl-f" (for find) then check the box "match entire cell contents."

    It's not in the coding, but it makes the coding work right.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,006

    Re: Find, copy, and paste marco

    There are several arguments to the Find method and it is rarely wise to only specify what to find, since the settings persist between searches and searches in the UI will affect code searches and vice versa. In addition to specifying what to find, you should specify LookAt:=xlWhole for a match on the entire cell, Lookin:=xlvalues or xlformulas as appropriate and you may wish to specify MatchCase:=true or false for case sensitivity.
    Everyone who confuses correlation and causation ends up dead.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find, copy, and paste marco

    Yes, yes, yes! Preach it, Romper!

    Never use a FIND command without Lookin:= and LookAt:= at a minimum. Always always always!


    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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