+ Reply to Thread
Results 1 to 6 of 6

Table Editing Using VBA

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Belfast
    MS-Off Ver
    Excel 2010
    Posts
    39

    Table Editing Using VBA

    Hi,

    I have the following piece of code

    Please Login or Register  to view this content.
    I have 32 different "Criteria1" each with a different three letter name. Could someone please advise me as to how I would go about writing a for each statement that would enable me to replace the 32 chunks of code with one simple paragraph that would greatly improve the efficiency of my program.

    Many thanks in advance.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Table Editing Using VBA

    One of many ways, just fill in the array:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-28-2013
    Location
    Belfast
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Table Editing Using VBA

    Worked a charm dude, thank you so much. Could you explain this line to me in a bit more detail:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Table Editing Using VBA

    The array is going to be referenced by the index number of each string in the array. We use "m" as the numeric variable.

    LBound(MyStrings)
    will return the index number of the first item in the array, this is usually 0 or 1. We could just USE 0 or 1 in this spot, but I'm lazy and don't bother to remember which types of arrays are 0-based and which are 1-based. So LBound to the rescue, does it for us.

    UBound(MyStrings) will return the index number of the last item in the array. Since you have 32 items that number is going to be 31 for 0-based arrays, and 32 for 1-based arrays. LBound figures out which is correct so we don't have to.

    This translates in the example given into either:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    It works fine either way.


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

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    Belfast
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Table Editing Using VBA

    Mate that's amazing stuff thank you so much. Just want to learn as much vba as possible so much to learn so little time....

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Table Editing Using VBA

    Pfft... all the time in the world.

+ 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. Small editing of vba - a table of contents since the second row
    By Remphan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2013, 07:01 PM
  2. Table Editing in a Protected Worksheet
    By avsimmons in forum Excel General
    Replies: 2
    Last Post: 08-09-2012, 12:07 PM
  3. editing a table using a vlookup
    By quiggdavid in forum Excel General
    Replies: 7
    Last Post: 04-06-2011, 07:09 AM
  4. Editing info in a table
    By buffalobill in forum Excel General
    Replies: 5
    Last Post: 11-29-2009, 06:42 PM
  5. Editing a pivot table
    By jennerifw in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-04-2005, 08: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