Custom vlookup function?

AceFI

Board Regular
Joined
Apr 20, 2012
Messages
91
hi all.
I'm wanting to create my own formula function, but not too sure where to begin..

basic; =WhichState(A1)


3931VIC
4000QLD
6000WA
2011NSW

<tbody>
</tbody>

at the moment i'm using a =left, plus a vlookup and its a bit messy, and it gets used in a ton of my spreadsheets..

any tips for getting started?

TIA
 
It's a good tiny bit of code that gets the job done. Luckily Australian post codes have a numeric regularity, UK and Canadian.
The only addition the OP may want would be how values not in any Case range are handled. Currently returns blank if code is Invalid. I would think it may be better to return something more definitive.

If I was in need for my own desk such a function, I would likely stick with Peter's type of solution, unless I was in PowerQuery/Data Model.
Usually three decent ways to accomplish the same end, it just depends on end-use as to which ones rise to the top.

After selecting the function and finishing the edit, you will likely have, which references where the code for the function is stored.
Code:
=Personal.xlsb!State(F4)

foiled by this editor doh! Should have been , "unlike UK and Canada."
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
One of things that may have been overlooked with any named range or worksheet lookup suggestion, and one of the reasons I went for the UDF, is the the following comment from the OP in post #1 . I could be wrong but I took "ton of my spreadsheets" to mean "ton of my workbooks" rather than "ton of my worksheets". I'm not sure the named range or lookup formula suggestions would lend themselves so well to that.
.. it gets used in a ton of my spreadsheets..

BTW, unless every postcode in the country is listed in the named range, the following change would need to be made (and carefully constructing the lookup table to be in appropriate order)
Make a named Range State that uses your Formula as the Refences = Vlookup(A1,named_range,2,<del>0 </del>1)


The other reason I gave a UDF was that the OP appears to ask for that (though I readily admit OPs often ask for something specific, not knowing a better alternative may be available).

Anyway, hopefully we hear back from the OP again regarding the error that seems to be happening with the UDF.
 
Last edited:
Upvote 0
hi all. sorry for the late reply. this worked; =Personal.xlsb!State(F4)
Good news! Whilst I mentioned moving the function to that workbook, I didn't add that detail & then didn't even twig that was causing the error you reported, sorry about that. Anyway, SpillerBD's picked up on it thankfully. :)
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,317
Members
449,218
Latest member
Excel Master

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