Results 1 to 3 of 3

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

Threaded View

vagonzalez I am trying to look up text... 03-24-2014, 05:23 PM
protonLeah Re: I am trying to look up... 03-25-2014, 01:39 AM
vagonzalez Re: I am trying to look up... 04-15-2014, 11:46 AM
  1. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,929

    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

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