Having trouble making UDF work with reference to Personal.xlsb

gmittar

Board Regular
Joined
Sep 16, 2013
Messages
62
Hi All,

VBA novice here, just getting into learning about User Defined Functions. I have a function (listed below), that if called from the sheet that I'm working in (inserted into a local module), works fine. However, if it's referred to in my Personal.xlsb, gives me an error message in VBE "Compile Error: Variable not defined" and highlights the "i" in "For i = 1 To StringLength"

I'm calling the function with =personal.xlsb!getnumeric(f4)

'This VBA code will create a function to get the numeric part from a string
Function GetNumeric(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If IsNumeric(Mid(CellRef, i, 1)) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetNumeric = Result
End Function

Appreciate your help.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Add this line
Code:
Function GetNumeric(CellRef As String)
[COLOR=#0000ff]Dim i as Long[/COLOR]
Dim StringLength As Integer
 
Upvote 0
Try

Code:
Function GetNumeric(CellRef As String)
Dim StringLength As Integer,[COLOR=#ff0000] i As Long, Result As String[/COLOR]
StringLength = Len(CellRef)
For i = 1 To StringLength
If IsNumeric(Mid(CellRef, i, 1)) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetNumeric = Result
End Function

M.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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