+ Reply to Thread
Results 1 to 6 of 6

Avoiding the use of ".select"

  1. #1
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Avoiding the use of ".select"

    In a recent thread, RoyUk wrote "The most important thing is to not select any sheets or ranges, doing so will slow your code."

    When I use the Macro Recorder it always returns something with ".select", for example:


    Please Login or Register  to view this content.
    What is the best way to code this without ".select" so that my codes stay lean and mean.
    Last edited by dagindi; 07-28-2010 at 04:43 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Avoiding the use of ".select"

    I think this is "lean and mean":

    Please Login or Register  to view this content.
    A lot of times with the macro recorder, you can take where one line ends with .Select and the next line begins with Selection. and just join them by deleting the Select/Selection verbiage and space in between.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Avoiding the use of ".select"

    Yo've got many false staements in the 1st With EndWith code. So u can erase them, I'm sure this wont affect on your code. Same as For borders..So shortened version posted below. please try this out and let me know if it works same as first-posted code.

    Please Login or Register  to view this content.
    Last edited by contaminated; 07-28-2010 at 04:02 PM.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Avoiding the use of ".select"

    Hi contaminated. Just wanted to point out that if the OP is trying to clear off existing borders, your code will not work.

  5. #5
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Avoiding the use of ".select"

    Dave,

    The macro you provided works perfectly.

    I will also be using "you can take where one line ends with .Select and the next line begins with Selection. and just join them by deleting the Select/Selection verbiage and space in between." as my rule of thumb to eliminate the .select/selection and hopefully speed up my macros.

    Thanks!!

  6. #6
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Avoiding the use of ".select"

    Contaminated,

    Thanks for the code. This particular report has borders and shading that I want to remove.

    In the end I took Dave's code and your recommendation to erase the false statements and its running smoothly.

    I don't know if I see a difference in the overall speed between having .select, but I am sure as these reports grow it will be beneficial.

    Thanks and I'll be adding to both of your reps...

    Cheers!!

+ 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