+ Reply to Thread
Results 1 to 2 of 2

Good practice for working with variables?

  1. #1
    Forum Contributor
    Join Date
    05-30-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    107

    Good practice for working with variables?

    When I create macro I often define my variables at the beginning of procedures, and then use them and pass them to other functions if needed. Like this:

    Please Login or Register  to view this content.
    Is this good practice or does this waste memory in some way?

    For example, would the following be better:

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Good practice for working with variables?

    Don't see any problems with either approach, though personally I would favour the first set of code - apart from one thing, I would declare all the variables at the top of the sub.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

+ 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] Private Variables: what are they good for (In VBA)? Non-technical/exp.-based guidance req.
    By joe31623 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2016, 09:19 PM
  2. UDF not working quite good
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-11-2014, 05:39 AM
  3. [SOLVED] Setting Variables - best practice
    By BremhillBob in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2014, 03:15 PM
  4. Working with Variables
    By Tim S in forum Excel General
    Replies: 4
    Last Post: 02-22-2011, 11:46 AM
  5. Excel 2007 : working with variables
    By envyjack001 in forum Excel General
    Replies: 0
    Last Post: 06-28-2009, 01:17 PM
  6. [SOLVED] Good Practice
    By Ardus Petus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2006, 04:10 PM
  7. [SOLVED] Which folder - good practice?
    By Sunbank in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2006, 09:35 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