View Full Version : Trouble implementing UDF's
ProspectiveCounselor
05-05-2013, 05:50 PM
Hello,
I'm new to UDF's since my interest in them came only a few hours ago. I'm having trouble implementing them. I once was able to just use A1 = padLeft("x",5)&":" to get
x :
but now I sometimes get a #NAME error on that. I was able to do it using PadLeft.PadLeft("x",5), but I don't want to have to do that. I think maybe the first PadLeft (before the dot) is the module name, but I didn't have to use the module name before I renamed it. How do I get standard access to it?
--Sabrina--
Admin
05-05-2013, 07:57 PM
Hi Sabrina,
Welcome to ExcelFox !!
Your code is incomplete, I guess. Post your whole code.
ProspectiveCounselor
05-06-2013, 05:44 AM
I don't think it's the code because only the method of calling it is the problem. Here is my code, though.
PadLeft, in Module called PadLeft
Function PadLeft(text, spaces)
If Len(text) <= spaces Then
PadLeft = Application.Rept(" ", spaces - Len(text)) & text
Else
PadLeft = text & " has " & Len(text) & " space(s). You are asking for " & spaces & " space(s)."
End If
End Function
PadRight
Function PadRight(text, spaces)
If Len(text) <= spaces Then
PadRight = text & Application.Rept(" ", spaces - Len(text))
Else
PadRight = text & " has " & Len(text) & " space(s). You are asking for " & spaces & " space(s)."
End If
End Function
Like I said, calling padleft("A",5) doesn't work, but calling PadLeft.PadLeft("A",5), does; calling padRight("A",5) doesn't work, as well, while PadRight.PadRight("A",5) does.
Here are print screens depicting what I'm doing.
http://www.fileden.com/files/2012/10/28/3361337/udf_formulas.png
http://www.fileden.com/files/2012/10/28/3361337/udf_values.png
I apologise for the size, but I don't have time to resize them atm because I have a term paper due in less than six hours.
Admin
05-06-2013, 09:10 AM
Hi,
Change your module name. Your UDF as well as function name are same, which causes the problem.
ProspectiveCounselor
05-06-2013, 08:07 PM
OK, that fixed the problem, I think. I say "I think" because I was getting a popup saying "User function type not defined" or something like that, but restarting Excel a couple of times fixed that. Thank you!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.