+ Reply to Thread
Results 1 to 9 of 9

Write a more efficient code

  1. #1
    Registered User
    Join Date
    04-20-2015
    Location
    Norway
    MS-Off Ver
    360
    Posts
    24

    Write a more efficient code

    Hi all!

    I’ve written a (copy-paste based) code to transform data, and it’s quite slow for thousands of companies. However, I lack the intuition for a better approach to the problem. If someone can help me out or point me in the right direction, I would be very thankful

    An example is attached.

    A description of the problem follows:
    I get datasets that consist of company data, where I need to transform the format. Every company comes with:
    - 1 row with Name
    - X number of rows with fixed information
    - Y number of columns with (time) variable data
    - 1 column with dates.


    The date-column causes the headers to be off by one column. Furthermore, some companies have no data for the selected period, and should be deleted altogether.

    The transformed data has one row for every date, and one column for every other datatype (fixed and variable).
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Write a more efficient code

    Hi Karl,

    Not all of your code is included in the sample

    It looks as though you can do some block deletions:

    Please Login or Register  to view this content.
    Last edited by xladept; 04-25-2016 at 11:35 AM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    04-20-2015
    Location
    Norway
    MS-Off Ver
    360
    Posts
    24

    Re: Write a more efficient code

    You're right, I'm sorry..
    It's fixed now!
    Attached Files Attached Files

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Write a more efficient code

    I'm sorry too - I edited the last post with an observation. I'll be looking at your code off and on for maybe another hour

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Write a more efficient code

    The first thing I would do would be to delete all the blank data rows.

    I will create a code snippet for you to try.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 04-25-2016 at 12:42 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Write a more efficient code

    Well, so far, just the block deletions for these two deletion routines:

    Please Login or Register  to view this content.
    AND

    Please Login or Register  to view this content.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Write a more efficient code

    Add this copy routine code change:

    Please Login or Register  to view this content.
    *Sample took 3.4s at start now down to 1.2s
    Last edited by xladept; 04-25-2016 at 01:13 PM.

  8. #8
    Registered User
    Join Date
    04-20-2015
    Location
    Norway
    MS-Off Ver
    360
    Posts
    24

    Re: Write a more efficient code

    Thank you both for replying
    I went with your advice (again), xladept, and ended up with a much shorter and faster code!

    Thank you for your time

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Write a more efficient code

    You're welcome!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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] VBA Delete Row Code - Need more efficient code to speed it up
    By matcapir in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2015, 04:32 PM
  2. Slow code- making code more efficient
    By ammartino44 in forum Excel General
    Replies: 4
    Last Post: 05-06-2015, 12:47 PM
  3. More efficient way to write this formula?
    By Destroy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2014, 10:31 AM
  4. [SOLVED] Trying to change verbose looping code into more efficient (and shorter) code please
    By dawatcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-03-2013, 07:43 AM
  5. Is there a more efficient way to write this formula
    By Excelsius in forum Excel General
    Replies: 8
    Last Post: 02-01-2012, 11:12 AM
  6. Most Efficient Way to Write Out Data
    By ld_pvl in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-09-2011, 04:01 PM
  7. Efficient Code
    By GregR in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-27-2005, 12:05 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