Results 1 to 5 of 5

Thread: Trouble implementing UDF's

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Rep Power
    0

    Trouble implementing UDF's

    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

    Code:
    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--

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi Sabrina,

    Welcome to ExcelFox !!

    Your code is incomplete, I guess. Post your whole code.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Rep Power
    0
    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
    Code:
    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
    Code:
    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.




    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.

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Change your module name. Your UDF as well as function name are same, which causes the problem.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Rep Power
    0
    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!

Similar Threads

  1. Question on UDF LookUpConcat
    By K2` in forum Excel Help
    Replies: 4
    Last Post: 05-07-2013, 10:25 PM
  2. Insert Picture in a Cell UDF
    By Admin in forum Download Center
    Replies: 10
    Last Post: 12-07-2012, 04:49 PM
  3. Passing a UDF as return type
    By Junoon in forum Excel Help
    Replies: 0
    Last Post: 05-05-2012, 05:26 PM
  4. Nth Largest Unique Value in an Array (UDF)
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 4
    Last Post: 03-07-2012, 12:34 PM
  5. UDF to Create In-Cell Chart in Excel
    By Admin in forum Download Center
    Replies: 0
    Last Post: 08-13-2011, 09:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •