+ Reply to Thread
Results 1 to 8 of 8

Code Optimization

  1. #1
    Forum Contributor
    Join Date
    10-31-2008
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    108

    Question Code Optimization

    Hi,

    I have the following code. It simple copy paste values and formatting from some cells to another and sort it ascending.

    But as I increasing the number of columns a lot, its taking ages.

    Is it possible to optimize it? Make it faster?

    Please Login or Register  to view this content.
    Download: https://drive.google.com/file/d/0B4n...ew?usp=sharing

  2. #2
    Forum Contributor
    Join Date
    10-31-2008
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    108

    Re: Code Optimization

    I also would like to make a question regarding the code.

    Its organizing ascending using ARRIVAL time as key. How can I change to use DEPARTURE time as key?

    Example, in here:

    Please Login or Register  to view this content.
    L column is ARRIVAL, N column is DEPARTURE.

  3. #3
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Code Optimization

    All of those Range().Selects can be put into one block:

    Range("L8:L500,N8:O500,Q8:R500,etc,etc,etc,etc").Select



    For the next block of code

    Do you really need to copy and Paste? cant you just set the cell value?

    eg

    Please Login or Register  to view this content.
    having just realised that you're also copying the format it would depend on whether that is important or could be done as a single job at the end.

    Im not sure if Im misreading your code but whats the purpose of the last block of 10 points? it appears to sort the sheet in 10 different ways, one after the other which (unless Im missing something) can be achieved by simply doing point 10?
    If someone has helped you then please add to their Reputation

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Code Optimization

    Quote Originally Posted by douglascaixeta View Post
    I also would like to make a question regarding the code.

    Its organizing ascending using ARRIVAL time as key. How can I change to use DEPARTURE time as key?

    Example, in here:

    Please Login or Register  to view this content.
    L column is ARRIVAL, N column is DEPARTURE.
    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-18-2014
    Location
    France
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Code Optimization

    There are some simple things to do as well for the speed :
    -Put on Application.ScreenUpdating = False at the begining and Application.ScreenUpdating = True at the end.
    -and it won't be very usefull there but when there are calculations : Application.Calculation = xlCalculationManual at begining and Application.Calculation = xlCalculationAutomatic at the end.

    It may be simple but you'll see the difference.

  6. #6
    Forum Contributor
    Join Date
    10-31-2008
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    108

    Re: Code Optimization

    Quote Originally Posted by pjwhitfield View Post
    All of those Range().Selects can be put into one block:
    Are you sure its possible? Pay attention that I'm jumping one column always. L yes, M no, N and O yes, P no, Q and R yes.

    Do you really need to copy and Paste? cant you just set the cell value?
    Formatting is very important.

    Im not sure if Im misreading your code but whats the purpose of the last block of 10 points? it appears to sort the sheet in 10 different ways, one after the other which (unless Im missing something) can be achieved by simply doing point 10?
    I think all of this is because I'm jumping one column at a time. So I believe its not possible to select everything, lets say A till D and paste all at once like this: A in M, B and C in O and P, D in R.
    The sheet is available to download, so you can see what the points are. Just separation of the columns.


    Quote Originally Posted by pjwhitfield View Post
    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    I don't really understand it then, because Key:=Range is for both. I will replace one and not select the other?

    Please Login or Register  to view this content.
    How this entire piece of code should look like? I will put N8:N500 twice?

  7. #7
    Forum Contributor
    Join Date
    10-31-2008
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    108

    Re: Code Optimization

    Quote Originally Posted by polooop View Post
    There are some simple things to do as well for the speed :
    -Put on Application.ScreenUpdating = False at the beginning and Application.ScreenUpdating = True at the end.
    -and it won't be very useful there but when there are calculations : Application.Calculation = xlCalculationManual at begining and Application.Calculation = xlCalculationAutomatic at the end.

    It may be simple but you'll see the difference.
    WOW!!! You gotta be kidding me?!?! That was freaking amazing! To almost 1 minute is down to 1 second! This is great. It should come in all code this lines directly. Its amazing.

    Thank you absurdly!

    I'm done with optimization. That is more I was expecting.

    But I would like to sort by Departure time, not Arrival time. How that can be done?

    Example, in here:

    Please Login or Register  to view this content.
    L column is ARRIVAL, N column is DEPARTURE.
    Last edited by douglascaixeta; 12-02-2014 at 05:06 PM.

  8. #8
    Registered User
    Join Date
    02-18-2014
    Location
    France
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Code Optimization

    Glad to see it helped, It did the same effect on me when I had tested that for the first time . Unfortunately i'm not very used to sorting... Good luck for next steps!

+ 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. Code Optimization for Fun
    By Mordred in forum The Water Cooler
    Replies: 15
    Last Post: 07-23-2011, 12:47 PM
  2. Optimization VBA code
    By ahmad123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2011, 05:35 PM
  3. Code optimization
    By d_omin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2010, 04:13 AM
  4. Code Optimization
    By adyan76 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-05-2009, 08:36 AM
  5. VBA optimization of code
    By Fazered in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2007, 12:36 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