+ Reply to Thread
Results 1 to 3 of 3

I am trying to look up text and return a value.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2011
    Location
    GA, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question I am trying to look up text and return a value.

    Brief explanation:
    I am trying to look up text and return a value.

    The key words I am looking up are contained in worksheet 1.

    Worksheet 2 contains a table with 3 columns. Column 1 is a work order number. Column 2 is a description of the work order with keywords embedded in there somewhere. Column 3 contains a status of the work order (closed, open, researching)


    I need to find the work order number and status of the work order for each keyword. Attached is a sample workbook. Help!

    My lookup dilemma.xlsx
    Last edited by vagonzalez; 03-24-2014 at 05:29 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,925

    Re: I am trying to look up text and return a value.

    One solution is to create User Defined Functions (UDF):
    Note: you may have to change the sheet name from "worksheet 2" to what ever your actual sheet name is
    Option Explicit
    Public Function WorkNum(ByVal ServerName As String) As String
        Dim Descriptions    As Worksheet, _
            LastDescript    As Range, _
            Testcell        As Range, _
            NamePosition    As Variant
            
        Set Descriptions = Sheets("worksheet 2")
        Set LastDescript = Descriptions.Cells(Rows.Count, "B").End(xlUp)
        
        With Descriptions.Range("B2", LastDescript)
            Set NamePosition = .Find(ServerName)
        
            If Not NamePosition Is Nothing Then
                WorkNum = NamePosition.Offset(0, -1).Value
                Exit Function
            End If
        End With
    End Function
    B2 =WorkNum(A2)


    Public Function Option Explicit
    Public Function WorkNum(ByVal ServerName As String) As String
        Dim Descriptions    As Worksheet, _
            LastDescript    As Range, _
            Testcell        As Range, _
            NamePosition    As Variant
            
        Set Descriptions = Sheets("worksheet 2")
        Set LastDescript = Descriptions.Cells(Rows.Count, "B").End(xlUp)
        
        With Descriptions.Range("B2", LastDescript)
            Set NamePosition = .Find(ServerName)
        
            If Not NamePosition Is Nothing Then
                WorkNum = NamePosition.Offset(0, -1).Value
                Exit Function
            End If
        End With
    End Function
    In C2: =WorkStat(A2)



    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
    Attached Files Attached Files
    Last edited by protonLeah; 03-25-2014 at 01:46 AM.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-24-2011
    Location
    GA, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: I am trying to look up text and return a value.

    Excellent, you da' man. I will test and start using asap!

+ 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. If cell contains certain text and certain text then return predefined text
    By fuzzhead in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-25-2014, 02:18 PM
  2. [SOLVED] function IF to return text based if text contains exact text
    By in nomine noctis in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-05-2013, 06:25 AM
  3. Replies: 2
    Last Post: 09-07-2013, 07:50 PM
  4. If cell contains text1, text2 or text 3 return this text, otherwise return X
    By bukmanodrama in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-26-2013, 09:24 AM
  5. Replies: 7
    Last Post: 01-24-2013, 06:55 PM

Tags for this Thread

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