+ Reply to Thread
Results 1 to 27 of 27

Variable Find reference to a column?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-18-2006
    Posts
    68

    Variable Find reference to a column?

    Simple question for someone,
    I want to have a find command run and use a varible defined from a column on the same sheet I am performing the find on.
    I can do everything with the exception of defining the column that the variable will work through when it is defining the find name.
    Anyone care to help?
    TIA
    Patrick

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    it always helps for us to assist you if you post your code so that we can see what you are trying to acheive and be able to give you better advice

  3. #3
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Mudraker is right ... your question needs clarification ...
    Are you looking for code along these lines ...
    Sub MyFind()
    Dim Myfound as Range 
    Dim Co As Range
    Set Co = Range("A1:A100") ' <----- adjust to your needs
    
            set myfound = Co.Cells.Find(What:=MyValue, After:=ActiveCell, _ 
                     LookIn:=xlValues, LookAt:= xlWhole, _ 
                     SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
                     MatchCase:=False) 
    
            if myfound is nothing then 
                ' code for find failed, what should happen here? 
                msgbox "some message here!" 
                exit sub 
            else 
                ' code for find succeeded, what should happen here? 
                myfound.activate 
            end if
    End Sub
    HTH
    Carim

  4. #4
    Registered User
    Join Date
    08-18-2006
    Posts
    68
    What the macro will be doing is going through a list of names, each name will become a variable in a find command, the find command will run on another sheet and when the name on the other sheet has been found it will copy a set of stats and paste them into the original sheet.
    The part I have no idea how to do is setting up the list and having the code run through all the names on the list and each time making that name a variable.
    Any clearer? I have not done any code for this yet so I cannot post any
    TIA
    Patrick

  5. #5
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Given the fact that all your names are in a range, you can loop in this range ...
    with i as row and j as column
    For i = 1 to whatever
    For j = 1 to whatever
    Cells(i,j).Select
    next j
    next i

    HTH
    Carim

  6. #6
    Registered User
    Join Date
    08-18-2006
    Posts
    68
    And so if I had a statement like
    Dim name As string
    name = activecell

    Making the variable name equal to the current cell selected in the list?
    Correct?
    Patrick

+ 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