+ Reply to Thread
Results 1 to 11 of 11

VBA custom function, Expected List Separator or )

  1. #1
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Question VBA custom function, Expected List Separator or )

    Hello, so I've never written a custom function before and I'm doing something that should be quite simple.

    I'm taking the VLOOKUP function, and creating a new function that does the *same* exact thing, except it simplifies the typing process. Take a look.

    Please Login or Register  to view this content.
    The goal is just to have a shorter function name, and to not have to type the quotation marks with the asterisks, I only won't need to type FALSE at the end of it every time. Thinking on it now I may even try to default the range as well.

    Either way, it doesn't seem to like my commas but I'm not sure why. the VLOOKUP function is working perfectly fine in my excel sheet when typed like this (in the cell that is): "=VLOOKUP("*itemname*",A1:D26,4,FALSE)" so I'm not sure why that isn't translating nicely to the function.

  2. #2
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    VBA custom function, Expected List Separator or )

    Please Login or Register  to view this content.



    Sent from my iPhone using Tapatalk
    Last edited by coolblue; 06-14-2014 at 09:54 PM.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA custom function, Expected List Separator or )

    When writing UDFs one doesn't include the arguments in the final assignment of the value of the function.
    Also, the data type of the arguments is given in the function declaration line, not a Dim statement.
    I'm also hesitant to use Range, Column and other common names of properties as the arguments to UDF's.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA custom function, Expected List Separator or )

    I think this is covered but this is my try:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Re: VBA custom function, Expected List Separator or )

    The code I ended up going with was this, and it works fine

    Please Login or Register  to view this content.
    I decided that I actually want to make the range and column static as well. I tried a few different things but none of them have worked so far. This was my last attempt but it just returns 0 all the time.



    Please Login or Register  to view this content.
    Thoughts?
    Thanks so much!

  6. #6
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Re: VBA custom function, Expected List Separator or )

    Double posted. Not sure how to delete this post though.
    Last edited by NicholasL; 06-15-2014 at 08:11 AM. Reason: double post

  7. #7
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA custom function, Expected List Separator or )

    Hi,

    <issing the correct range notation

    Please Login or Register  to view this content.
    Thanks

  8. #8
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Re: VBA custom function, Expected List Separator or )

    Ahhhhh, I see.
    Great, thanks to all who contributed!

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA custom function, Expected List Separator or )

    My thinking is that hard coded values in a function can be a pain down the line. Rather than have
    =cvl("Smith") in a cell, I'd prefer to use the UDF

    Please Login or Register  to view this content.
    and put =VLOOKUP(containString("Smith"), Range($A$1:$D$40), 4, False) in the cell.

  10. #10
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Re: VBA custom function, Expected List Separator or )

    It's some solid advice but what doesn't work for me is just the length of the formula. The workbook is personal, by which I mean it's not for work or a client or anything like that, and the way I have it set up I don't foresee ever needing to change those other values (and if I do, I can effectively change it for *every* cell containing my UDF by making a slight edit to the code, rather than changing every cell containing one of these -- which is going to be a lot).

  11. #11
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA custom function, Expected List Separator or )

    I totally get what mike says. We think we have all under control but later on a few months from now something starts failing and we cannot find what its and we already forgotten that we made that range hard coded. by the way your VLOOKUP formula is pretty small, I wonder if you will add more to it.

    Good Luck

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Complie Error: Expected: list separator or (
    By Poornima Rajgopal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-07-2013, 12:32 PM
  2. [SOLVED] Continue code on next line: Compile Error: expected list separator or )
    By ike609 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-05-2012, 08:28 AM
  3. compile error – expected : list separator or )
    By mdavid800 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2011, 04:59 PM
  4. Replies: 1
    Last Post: 03-23-2006, 01:10 PM
  5. Comma separator for custom Currency
    By Bald Eagle in forum Excel General
    Replies: 0
    Last Post: 01-16-2006, 07:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1