+ Reply to Thread
Results 1 to 5 of 5

VB - Need to optimise/alternative to copy and paste

  1. #1
    Registered User
    Join Date
    10-12-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    VB - Need to optimise/alternative to copy and paste

    Hi Everyone,

    I am a noob at vb so sorry if i do something stupid.

    I am trying to auto fill a report from a log file by importing the csv file and rearranging the data.

    There is lots of copy and pastes in two loops which works in debugging but is takes ages and is prone to crashing. (20 minutes to run)

    Can anyone give me ideas to speed up the process.

    I already have screen update and calculations update to False and manual.

    Thanks in Advance.

    The problem code is below:

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VB - Need to optimise/alternative to copy and paste

    Maybe you can attach the file that contains the macro so its easy to test it and find the problem areas.

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VB - Need to optimise/alternative to copy and paste

    The first thing to look at would be the number of .Select and .Activate commands you have in your code.

    In VBA it's hardly ever necessary to activate or select objects before you use them, so

    Please Login or Register  to view this content.

    Can be cut down to

    Please Login or Register  to view this content.
    Last edited by Andrew-R; 10-13-2011 at 03:37 AM.

  4. #4
    Registered User
    Join Date
    10-12-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VB - Need to optimise/alternative to copy and paste

    Ahhh,

    That is a much better way of doing things, I didn't realize how slow the activating and selecting was.

    That decreased it from 20 minutes to 1 minute.

    There was an extra comma in there so the code is :

    Please Login or Register  to view this content.
    I have to admit, i had to go through that line about 10 times to trace exactly where it was going!!

    I have changed the code in other areas to not use so much select and activate.

    I will attach the files next time, sorry if it was an inconvenience.

    Thanks heaps Andrew for your help, I really appreciate it.

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VB - Need to optimise/alternative to copy and paste

    Happy to have helped, and sorry for the extra comma.

    The important things are that so long as you have two ranges the same size you can just assign values from one to the other, e.g.

    Please Login or Register  to view this content.

    If you want formatting, colours and so forth, as well as values, you can go with:

    Please Login or Register  to view this content.

    No need for activating and selecting all over the place, which, as you've found out, really slows things down.

+ 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