+ Reply to Thread
Results 1 to 5 of 5

Very inefficient code because of different sizes of arrays, how do i shorten my code?

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Very inefficient code because of different sizes of arrays, how do i shorten my code?

    Hi guys,

    I have just started working with VBA and since I like to work as efficient as possible, I was wondering how I could shorten the code below. For instance, now I am using a very similar code with all of the 4 select cases, this because I am using different sizes of arrays and I dont know how to do it in another way. I would like to use these bits without having to copy and then modify them slightly every time. Does anybody now a solution to this problem? In advance, thanks very much for looking at my problem!

    Bram

    Please Login or Register  to view this content.

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

    Re: Very inefficient code because of different sizes of arrays, how do i shorten my code?

    I haven't been through this in detail, but there's no reason to assign values to the arrays until after you've decided which case of i you're processing. So, based on the value of i, could you not just populate the array you need and then all of the cases will be generic.

    So, all the case statement is used for is to determine which cell to split - the array is always given the same variable name, and then you only need one occurrence of the loop.

    Does that make sense?

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Very inefficient code because of different sizes of arrays, how do i shorten my code?

    Use one array, setting it in the Select Case.

    Something like this.

    Please Login or Register  to view this content.
    Note - this won't make the code any quicker.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Very inefficient code because of different sizes of arrays, how do i shorten my code?

    Hi Andrew, thanks for the very fast reply. I totally see your point, great to have a quick clear view on my problem, I am going to try I out now!

  5. #5
    Registered User
    Join Date
    12-18-2012
    Location
    Tilburg, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Very inefficient code because of different sizes of arrays, how do i shorten my code?

    Andrew and Norie, thanks very much, works perfectly!!

+ 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