+ Reply to Thread
Results 1 to 6 of 6

Excel 2003 VBA: Find Method with Variable

  1. #1
    Registered User
    Join Date
    02-15-2011
    Location
    Bandera, Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Excel 2003 VBA: Find Method with Variable

    My problem is with the line beginning "Selection.Find."

    I want it to paste the clipboard contents into the search box, but it's
    remembering the specific value used when I set up the macro (i.e. copied the
    keystrokes).


    Please Login or Register  to view this content.
    Thanks for any help
    Last edited by DrNyet; 02-18-2011 at 08:41 AM. Reason: add code tags for newbie PM rules

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,059

    Re: Excel 2003 VBA: Find Method with Variable

    You need to get the search value from "somewhere". This could be from an InputBox or by putting the data in a cell. The value in the cell could be from a Data Validation drop down box based on data in the spreadsheet, that is, a list of (unique) values.

    Let's say the data you want to search for is in cell A1, the line would look like:

    Please Login or Register  to view this content.

    But you don't need to select the column first; you can use:

    Please Login or Register  to view this content.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Excel 2003 VBA: Find Method with Variable

    TMShucks is correct in that using a cell is probably better than the clipboard, you don't really need to copy it into memory first.

    But this routine WILL put the current clipboard contents into a usable variable:

    Please Login or Register  to view this content.

    To use this method you will need to add a reference to Microsoft Forms 2.0 Library. (VBA > Tools > References)
    _________________
    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!)

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Excel 2003 VBA: Find Method with Variable

    Based on your original code:
    Please Login or Register  to view this content.
    I assumed you were copying back to the current workbook.

    It also appears that this is probably inside a loop, in which case all the selecting you are doing is unnecessary and slows the code down - if you post the full code, I'm sure we can streamline it.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel 2003 VBA: Find Method with Variable

    e.g.

    Please Login or Register  to view this content.



  6. #6
    Registered User
    Join Date
    02-15-2011
    Location
    Bandera, Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel 2003 VBA: Find Method with Variable

    Thank you for the responses. You have been very generous.

    This is the entire code other than the subroutine name and close.

    The goal is to enter a item number in a "New" workbook and have it retrieve the description and color from a Master workbook, and add those to New, to be used as a list for production.

    I am sadly unversed in VBA and only know enough to look for examples to incorporate. The two workbooks involved are small so speed is not much of an issue although I appreciate any improvement and the opportunity to understand more about it.

+ 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