+ Reply to Thread
Results 1 to 4 of 4

Lookup name in list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-02-2013
    Location
    Netherlands
    MS-Off Ver
    Office 365 (2013)
    Posts
    268

    Lookup name in list

    Hey,

    I'm really bad in VBA, but I think its fun to try some things.
    Got a script now so when someone types in a new range of info, it will be added in the datasheet

    This datasheet looks like this:
    [number] [name] [surname] [adress] [extrainfo]
    [1] [Frans] [Flipkip] [whocares] [ ]
    [2] [Tony] [Mafkees] [noidea] [ ]

    When I have Flipkip on my first page in a cell (say A1) <-- this cell is always the same
    And info in cell A2
    Then I want, when I press a button, to return the info from cell A2 into datasheet extrainfo column in row 2

    When I have Mafkees on my first page in a cell (say A1)
    And info in cell A2
    Then I want, when I press a button, to return the info from cell A2 into datasheet extrainfo column in row 3

    If someone tells me to upload an example I will have to disappoint him/her. My sheet is so confusing that I can better just try and explain it, so I have 2% chance someone will understand it and is willing to help.
    Last edited by Evolta; 09-17-2013 at 09:39 AM.

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Lookup name in list

    Create a module in your workbook and add the following code:

    Public Sub copyInfo()
    On Error Resume Next
    
    '#
    '# declare private variables
    '#
       Dim strLookupKey As String
       Dim strExtraInfo As String
       Dim objFound As Excel.Range
    
    '#
    '# assuming sheet1 is the input worksheet containing cell A1 and A2 as per
    '# your example
    '#
       With ThisWorkbook.Worksheets("Sheet1")
          strLookupKey = .Range("A1").Value
          strExtraInfo = .Range("A2").Value
       End With
       
    '#
    '# search for the lookup_value in the data worksheet, assuming the data worksheet is called
    '# Sheet2 and the search must be performed in column C - using the column layout as described
    '# in your post
    '#
       With ThisWorkbook.Worksheets("Sheet2")
       
       '#
       '# conduct a search; when the search argument is found, the objFound range object will contain a pointer
       '# to the cell in column C holding the argument searched - you can play with the parameters to make the
       '# search more or less restrictive (match case, whole or partial cell value matching etc)
       '#
          Set objFound = .Cells.Find(What:=strLookupKey, After:=Cells(1, "C"), LookIn:=xlValues, LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)
          
       '#
       '# if the search text was found, the target column (extra info) can be updated with the extra info provided in
       '# cell A2 - the cell to update can be found by moving two columns to the right from the cell holding the found
       '# search argument
       '#
          If Not objFound Is Nothing Then
             objFound.Offset(0, 2).Value = strExtraInfo
          Else
             MsgBox "Sorry but the name " & Chr$(34) & strLookupKey & Chr$(34) & " could not be found"
          End If
          
       End With
    
    End Sub
    Add a button object to your first worksheet and subsequently link the button to the above routine - change the names of the worksheets in the code provided to meet your requirements
    If you like my contribution click the star icon!

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Lookup name in list

    Maybe:

    Sub Evolta()
    Select Case Range("A1").Value
        Case Is = "Flipkip"
            Range("A2").Copy Sheets("extrainfo").Range("A2")
        Case Is = "Mafkees"
            Range("A2").Copy Sheets("extrainfo").Range("A3")
    End Select
    End Sub

  4. #4
    Forum Contributor
    Join Date
    09-02-2013
    Location
    Netherlands
    MS-Off Ver
    Office 365 (2013)
    Posts
    268

    Re: Lookup name in list

    First answer worked perfect for what I wanted. 10/10!!

    Don't really think that your idea works in my case John. Since the data can contain more and more names, it will have to be updated each time a new name is edited. (at least thats what it looks like)

    I find it amazing how far I'm getting with 0% experience and 90% google and 10% questions

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Lookup a value in list and return a value from the same list
    By ahsng in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-16-2012, 04:34 PM
  2. lookup list
    By loner2003 in forum Excel General
    Replies: 7
    Last Post: 03-11-2010, 12:19 PM
  3. Lookup Last Value in List
    By kasimagj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2008, 05:52 PM
  4. Lookup and list
    By Voodoodan in forum Excel General
    Replies: 5
    Last Post: 05-25-2006, 02:10 PM
  5. Lookup a cell in a list to see if it is in the list
    By quimrider in forum Excel General
    Replies: 3
    Last Post: 12-09-2005, 02:06 PM

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