+ Reply to Thread
Results 1 to 8 of 8

STRANGE problem when passing an email address to function

  1. #1
    Registered User
    Join Date
    10-05-2018
    Location
    Milan
    MS-Off Ver
    2019
    Posts
    34

    STRANGE problem when passing an email address to function

    Hi,
    I need to check the validity of email addresses (with hyperlink).

    I found a nice function and it works, unless the email address has trailing spaces (they are not considered at all).

    It seems to me that Excel 2019 automatically eliminates the trailing spaces when passing the email address when in reality the data in the cell is WITH trailing spaces.

    Let's say I have this email address in A1: "john at gmail.com " (note the space at the far right).


    In the VBA function I pass the A1 value to strEmail

    If I check the lenght of the string passed into the function or the lenght of the trimmed string, they're the same.

    I also checked in VBA Editor the real time values of variables and the string I pass is already without spaces.

    Even removing the hyperlink from the cell doesn't change things.
    How can I solve this problem?


    Thank you very much for your time.

    Matt

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: STRANGE problem when passing an email address to function

    Welcome to the Forum Matt7272 !

    There is no way to answer this without seeing the code you are using and how you are using it. Attach a file with the code and at least example you are describing with both the cell with an email address and how you are calling the function.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-05-2018
    Location
    Milan
    MS-Off Ver
    2019
    Posts
    34

    Re: STRANGE problem when passing an email address to function

    Hi,
    here's the file.

    Thank you!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: STRANGE problem when passing an email address to function

    The problem is in the function TrueTrim. It modifies the input argument, which is a poor coding practice for a function. In VBA, the default argument mode is ByRef, so the modified argument is updated in the caller. The function should really use a local variable to do this, but the easiest fix is to explicitly use ByVal.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-05-2018
    Location
    Milan
    MS-Off Ver
    2019
    Posts
    34

    Re: STRANGE problem when passing an email address to function

    Hi 6StringJazzer,
    so just by removing "ByVal" it now works!
    I didn't know it could have such an effect, I've never bothered to change or remove "ByVal" in any of my functions! (Not that I made a ton!
    Thank you very very much!

    Matt

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: STRANGE problem when passing an email address to function

    I didn't remove it, I added it. ByRef is the default, so I added ByVal.

    ByRef means that when the argument is referenced in the function code, it is by address. Any changes made to that argument affect the the value of the variable that was passed by the caller.

    ByVal means that a copy of the argument is made to be available locally by the function code. Any changes to that argument are local to the function, and do not affect the caller.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: STRANGE problem when passing an email address to function

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.

  8. #8
    Registered User
    Join Date
    10-05-2018
    Location
    Milan
    MS-Off Ver
    2019
    Posts
    34

    Re: STRANGE problem when passing an email address to function

    Yes, sorry!
    I first looked at the other function!

    Thanks again very much!

+ 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. [SOLVED] vba email send from excel - ignore second email address if "ENTER EMAIL ADDRESS"
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2016, 07:22 AM
  2. Replies: 1
    Last Post: 03-08-2012, 01:57 PM
  3. passing cell address to function
    By david90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2011, 01:43 PM
  4. Problem with passing variables to function
    By rasx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2011, 04:44 AM
  5. Problem passing value to function
    By prod75 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-15-2009, 10:21 AM
  6. passing argument in a function as integer problem
    By ina in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2006, 11:55 AM

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