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
- Copy the Excel VBA code
- Select the workbook in which you want to store the Excel VBA code
- Press Alt+F11 to open the Visual Basic Editor
- Choose Insert > Module
- Edit > Paste the macro into the module that appeared
- Close the VBEditor
- Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
Bookmarks