+ Reply to Thread
Results 1 to 11 of 11

Notation of Excel Range

  1. #1
    Registered User
    Join Date
    09-17-2010
    Location
    Aalsmeer, the Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Notation of Excel Range

    Hello Everyone,

    I got a question related to code structure.
    (I got a fairly thorough understanding of Excel VBA and the Object Model)

    to refer to range, in a subroutine, one could either Type
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Things can get more detailed, for example:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    While method 2 is shorter, i would prefer method one, because it is easier to understand, and more clear as to which objects i refer to, code wise.

    My question is:
    if there is not any difference in speed, why use method 2?
    Last edited by Mark Heuckeroth; 09-17-2010 at 06:38 AM.
    Your constructive critisism is greatly appreciated!

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Notation of Excel Range

    or
    Please Login or Register  to view this content.
    method 2 should be 'slower' than method 1.
    If speed differences are indiscernable you could use the criterion 'readability' to choose between the methods.



  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Notation of Excel Range

    Use of [ ] is as you imply utilising Evaluate

    Worth mentioning on that basis that if you use shorthand (without the Evaluate statement) you can affect the output, eg:

    Please Login or Register  to view this content.
    As for range referencing ... I think most would argue [ ] to be "bad-practice" and some say slower than using Range / Cells etc but I confess I don't have the knowledge to back either up I'm afraid so will let others argue that one.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Notation of Excel Range

    v2 is equal to v3 if...
    Please Login or Register  to view this content.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Notation of Excel Range

    I thought it was quite apparent that I was highlighting the differences that occur when passing Strings...

  6. #6
    Registered User
    Join Date
    09-17-2010
    Location
    Aalsmeer, the Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Notation of Excel Range

    Thanks for the reply's so far.

    As to learn VBA the web has been of great help to me, as for notation it sometimes raises questions for what to use

    for example the use of With...End With

    sometimes i read:
    - try to avoid double with statements
    and i do agree with that.. but on the other hand you read
    -- use with...end with instead of object variables.
    And i also agree with that, but sometimes you get into that situation.. and then which of the following would be preferred?

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    and why.

    EDIT: i always prefer to use single With statements
    Last edited by Mark Heuckeroth; 09-17-2010 at 05:13 AM. Reason: remark.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Notation of Excel Range

    I would use variables for both objects and I would have no problem with nested With statements.
    Remember what the dormouse said
    Feed your head

  8. #8
    Registered User
    Join Date
    09-17-2010
    Location
    Aalsmeer, the Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Notation of Excel Range

    Quote Originally Posted by romperstomper View Post
    I would use variables for both objects.
    Because of late binding, or in general?

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Notation of Excel Range

    @DonkeyOte

    I read your post as if you wanted to illustrate that using [] sometimes gives a different result from using Evaluate. We are on the same track again

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Notation of Excel Range

    Quote Originally Posted by Mark Heuckeroth View Post
    Because of late binding, or in general?
    In general. Makes debugging easier and the code more readable IMO.

  11. #11
    Registered User
    Join Date
    09-17-2010
    Location
    Aalsmeer, the Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Notation of Excel Range

    Thanks for the feedback everyone.
    I'ts good to know of a place where you can get feedback to more advanced questions.

    Mark.
    Last edited by Mark Heuckeroth; 09-17-2010 at 06:39 AM. Reason: everyone, no gender.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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