Excel VBA UDF

Young_Money

New Member
Joined
Jul 8, 2011
Messages
23
I am trying to make a UDF that prints the text next to the column that is entered.
Here is an example of what my excel sheet looks like
A / B / C
Customer Initials Location
blahblah JJ Virginia
blah GL Texas
hello LO California
ohai FE Georgia
lalala SL New York
adsf JL Washington

I want to be able to type in the initials and get the location returned.
For example, if i type in =getlocation(SL) into any cell, it would return New York
You cannot really see what the sheet looks like here, but it is supposed to be three different columns.
Can anybody help me out with how to do this please?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I see how to use vlookup. However, the assignment is that I need to make a custom function, and not use any existing functions.
 
Upvote 0
assignment eh....? homework? why you ask for help?

I'll give you hints, but not do your work for you.

1. find your string in the correct column, and then
2. return an OFFSET for the next column
 
Upvote 0
Thanks rsxchin! I didn't want anybody to do it for me, I just wanted some tips so I would be able to do it because I actually want to learn it.
 
Upvote 0
Here is what I have. I just started VBA yesterday, so I am REALLY new to this. I don't really know what is wrong with it...


Function CustomLookup(initials As String) As String
Dim r As String
For Each r In Range("B:B")
If r.String = r Then
CustomLookup = r.Offset(0, 1).Value
Exit Function
End If
Else
CustomLookup = "Not Found"
End If

End Function

My idea is that when i enter an initial such as FE, it will look in the column B for FE. If it is there, then it will look at the column to the right of it, and print it out Georgia. But I do not know how to fix the syntax error here..
Any more hints please?
 
Upvote 0
hmm actually
would I be able to use vlookup to see if i could find a match in column b
and it matches, then return the offset 1 to the right?
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top