How to make the VBA UDF function run in all worksheets?

Young_Money

New Member
Joined
Jul 8, 2011
Messages
23
Hi guys.. My question today is how do I get my UDF to run in all worksheets of my excel file?

Here is the code I have that runs on one worksheet

Function Custom_Lookup(ByVal Client_Initials As String) As String
Dim r
For Each r In Range("B:B")
If r = Client_Initials Then
Custom_Lookup = r.Offset(0, 1)
Exit Function
End If
Next

Custom_Lookup = "Not Found"

End Function

It runs the worksheet NewContractOrder
However, I want it to be able to run on a worksheet top opportunity and opportunity as well.
All 3 worksheets have the same format, so the function will work correctly on all of them..but my question is how to get the function to work in all 3 excel sheets instead of just NewContractOrder.

Any help would be appreciated!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
If you place the custom function in a standard module (not a worksheet or ThisWorkbook module) then it should be available on any sheet in the workbook.
 
Upvote 0
I see.. how would I go about doing that?
I know to create a module I go to macro then VBE then right click modules and click create a new module.. but how do I make a standard module?

Sorry I am really new to VBA..
 
Upvote 0
Oh I see..
I think I did make a standard module to run this UDF
However, when I delete the first sheet, the customlookup function does not work anymore..
Do you know why?

I want the function to be able to run independently..
so it will look at the initials row for any worksheet and print out the box to the right of it
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,284
Members
452,902
Latest member
Knuddeluff

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