+ Reply to Thread
Results 1 to 5 of 5

Removing Inefficent Code

  1. #1
    Registered User
    Join Date
    08-12-2010
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Removing Inefficent Code

    I have several instances of code that repeats for different variables, cells, and ranges. Being new to vba programming I need help in trying to condense and streamline the code that I am using if possible. This first code sample is repeated 5 times:
    Please Login or Register  to view this content.
    This second code sample is repeated 10 times:
    Please Login or Register  to view this content.
    I am also attaching a copy of the entire workbook. The above code is in the Sheet1, worksheet activate sub.
    Attached Files Attached Files
    Last edited by hchurch; 11-24-2010 at 02:37 PM. Reason: Issue Resolved

  2. #2
    Registered User
    Join Date
    11-12-2010
    Location
    Pisek, Czech republic
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Removing Inefficent Code

    Hi,

    the values for different sheets and cells You can hold in an array and then go through it using a For-Next cycle. But as for the different variables... I do not know, if it is possible. What about to use an array here, too, and instead of VarA, VarB... call them aVar(1), aVar(2)...?

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Removing Inefficent Code

    First have a look into 'passing arguments"

    instead of

    Please Login or Register  to view this content.
    you'd better use:
    Please Login or Register  to view this content.
    And plunge into 'loops'

    Please Login or Register  to view this content.



  4. #4
    Registered User
    Join Date
    08-12-2010
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Removing Inefficent Code

    Thanks snb. That is getting closer to what I was looking for. However, your code iterates through columns 4, 10, 16, 22, 28:
    Please Login or Register  to view this content.
    I need to process columns 4 & 10 as a set, then the next iteration needs to process columns 5 & 11, etc. Each step uses a different set of comparison variables for the intCountMin & intCountMax variables.

  5. #5
    Registered User
    Join Date
    08-12-2010
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Removing Inefficent Code

    Thanks snb. I figured out how to get my iterations to work the way I want.
    Please Login or Register  to view this content.
    Appreciate the help. Now I can apply that to other procedures and greatly reduce the amount of coding in this workbook.

+ 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