+ Reply to Thread
Results 1 to 5 of 5

Set Variable or object Nothing

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Set Variable or object Nothing

    Hi,

    Normally, if we use ws As worksheet or wb As workbook, at the bottom of code, we will write Set ws =Nothing / Set wb =Nothing


    How about if we use rng = Worksheets("ORIGINATOR").Range("B" & j & ":B" & i), Do we need to write Set rng =Nothing?

    then, I'm just want to know what is the important of set variable to "nothing"

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Set Variable or object Nothing

    You do not need; it is a good programming practice releasing the memory on object variables once the code has been executed.

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Set Variable or object Nothing

    Hi AB33,

    So, does it means that the set variable to "Nothing" only applicable to Object but the range is NOT required ?.

    Any impact to VBA code which lead to run-time error / any errors ?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Set Variable or object Nothing

    Object variable and arrays can be erased. Range could be an object variable. It does not mean a lot, you are emptying the variable, that is all.
    It can lead to an error if you release the object, but trying to refer it again on any code or part of the code, hence you see it at the bottom of a code.

  5. #5
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Set Variable or object Nothing

    Thanks for a good explanation.

+ 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. Replies: 2
    Last Post: 08-22-2014, 03:55 AM
  2. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  3. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  4. Object Name from a Variable, Doing Same Action to Multiple Object
    By 4Ferdinand in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2011, 02:05 AM
  5. Object Variable Not Set Error on Selection object
    By Jean in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-24-2006, 01:50 PM

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