+ Reply to Thread
Results 1 to 4 of 4

Shorten Code with arrays

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Surrey, BC
    MS-Off Ver
    Excel 2016
    Posts
    84

    Shorten Code with arrays

    Hi there, I have been trying to simplify code I wrote to be smaller and more efficient but I seem to be stuck with finishing it.

    Further down is what I have so far.

    Here is a sample of the full code... the full code has the rest of the weekday, I have only include two days (Sunday and Monday)

    Please Login or Register  to view this content.

    Here is what I have so far...

    My problem is that I'm not sure how to increment the letters in RED or the numbers in RED.

    Here is the hierarchy of which needs to go with which...

    Sunday
    - chksft1
    - "A"
    - 1,2
    - chksft2
    - "C"
    - 3,4
    - chksft3
    - "E"
    - 5,6

    Monday
    - chksft1
    - "H"
    - 8,9
    - chksft2
    - "J"
    - 10,11
    - chksft3
    - "L"
    - 12,13

    You can see the letters and numbers skip an extra one in between each weekday.

    Is it even possible for me to shorten this code?

    Please Login or Register  to view this content.
    Thanks
    Craig

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Shorten Code with arrays

    Try something like this (not tested).

    Please Login or Register  to view this content.
    The x*7 and the y*2 act like step sizes for the loops
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    10-18-2012
    Location
    Surrey, BC
    MS-Off Ver
    Excel 2016
    Posts
    84

    Re: Shorten Code with arrays

    Absolutely Awesome AlphaFrog!

    Ran a test on the math... everything incremented as it should.
    Inserted the code in my application... and it worked like a charm.

    Now you have me thinking about some of my other long procedures...
    I will see if I can use your technique to solve the rest on my own... we'll see if I can do it without having to post again. But I doubt it.

    Thanks for your amazing help!

    Craig

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Shorten Code with arrays

    You're welcome. Thanks for the feedback.

+ 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] How to Shorten my VBA Code?
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2014, 06:07 AM
  2. [SOLVED] Is it possible to shorten this code?
    By aaaaaaiden in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-12-2014, 11:05 AM
  3. [SOLVED] Very inefficient code because of different sizes of arrays, how do i shorten my code?
    By Brammer88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 04:49 PM
  4. shorten this code
    By khalid79m in forum Excel General
    Replies: 1
    Last Post: 05-15-2007, 06:38 AM

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