Results 1 to 16 of 16

Learning differences between ByVal and ByRef

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Learning differences between ByVal and ByRef

    I am trying to learn the differences between ByVal and ByRef. Below is a summary of what I have currently learned (or think I have ):
    1. Change original variable passed as argument: ByVal = can not change (passes a copy of the value only), ByRef = can change (passes the original reference) (hence their names)
    2. Passing Arrays: ByVal = Can't do (error), ByRef = Always use for passing arrays as arguments
    3. Passing objects: ByVal = Can not use on objects? ByRef = Always?
    4. Speed: ByVal = slightly slower, ByRef = slightly faster
    5. Argument type: ByRef = must be same variable type passed? ByVal = ?
    6. If not declared: ByVal = not default, ByRef = Default


    My questions:
    1. If there is anything I have incorrect in the above, could someone please let me know?
    2. Is there anything important missing from my summary that I should be learning?
    3. I fail to see any benefits of using ByVal over ByRef (unless you are paranoid about the possibility of altering the original variable). Or am I missing something big here? Please enlighten me if so.

    Thanks for any help/corrections.
    Last edited by mc84excel; 06-28-2013 at 03:26 AM. Reason: Corrections made
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

Thread Information

Users Browsing this Thread

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

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