+ Reply to Thread
Results 1 to 4 of 4

VBA Solution to Copying Command Buttons and Shapes

  1. #1
    Forum Contributor
    Join Date
    12-02-2010
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2013, 2016
    Posts
    100

    VBA Solution to Copying Command Buttons and Shapes

    Hello All,

    I haven't posted in a while as I try to be relatively self reliant and solve my own issues, but this one would save me about a day of copy paste so i'm asking for help. I have a series of hide/unhide functions for different rows that currently take the form of one command button and two shapes (with bound macros) per 11 rows. This is for a survey/analysis form and so I may need as many as 250 sets of 11 rows. I already have all of the macros generated using as little changing variables as I can so that I just change one variable for each iteration, but the copying of the actual command button and shapes for each of the 250 would be very tedious. The second part is that I can hit ctrl+v just as fast as the next guy, but having them located properly upon pasting would be a great feature to have in the code.

    To summarize, I have a command button is rows 2, 13, 24, a shape bound to similar macros in rows 3, 14, 25, and a second shape with another type of macro in rows 4, 15, and 26. This makes up three (3) iterations of my inspection form, and to cover the scope of what I do 250 is the number I am looking for in total. If my math is correct that would mean the last set of command button and shapes would occupy rows 2,741, 2,742, and 2,743. I would not like to do this by hand. If anyone has a solution please let me know. I have attached my spreadsheet for your perusal and/or use.

    Thanks,

    DarkF1ame

    Book2.xlsm
    Last edited by DarkF1ame; 02-16-2016 at 05:55 PM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: VBA Solution to Copying Command Buttons and Shapes

    Hi there,

    Take a look at the attached workbook and see if it does what you need.

    It uses the following code:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your own requirements.




    I had a look at the code which you're using to display/hide data rows as required. This uses 78 lines of code per set of 11 data rows, and when you multiply that by 250 sets of data rows it amounts to a LOT (19,500 lines) of code to maintain! This is very significant if you ever need to change any of your code, because you're going to have to make those changes in each one of 250 separate locations - doing it is bad enough, but ensuring that it's been done in ALL of those locations is the stuff that nightmares are made of.

    The attached version of your workbook uses a modular approach to the VBA, which means that it can process as many sets of data rows as you are ever likely to need, and uses only 107 lines of code in total - not a bad reduction!

    The code used is as follows:

    Please Login or Register  to view this content.
    As before, the highlighted values may be altered to suit your own requirements.



    Anyway, hope you find the above useful/interesting - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    12-02-2010
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2013, 2016
    Posts
    100

    Re: VBA Solution to Copying Command Buttons and Shapes

    Greg M,

    Thank you so much! The complete redesign of the code is amazing and way beyond my abilities in VBA at the moment. Thanks again, i will probably be picking parts of this code out to use elsewhere for a long time.

    Issues solved, will mark it as such in the post title.

    DarkF1ame

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: VBA Solution to Copying Command Buttons and Shapes

    Hi again,

    Many thanks for your very prompt feedback and also for the Reputation increase - much appreciated

    I'm very pleased that I was able to help - it was an interesting project for me.

    Please feel free to shout if there's any further information you think I can help you with.

    Best regards,

    Greg M

+ 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] Command Buttons Not Copying to the Designated Cell
    By Ataraxicatom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 02:38 PM
  2. [SOLVED] Delete Buttons made from shapes when copying sheet to new workbook
    By Bflare in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-27-2014, 09:44 AM
  3. Useform Code - 12 Command Buttons dependant on other command buttons
    By darrenkaye in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 10:58 AM
  4. Master Command Button to call on other Command Buttons located in other Workbooks
    By MrNickRegan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2013, 07:57 PM
  5. [SOLVED] Copying a sheet without copying the command buttons
    By LeapingLizard in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 10-27-2012, 09:17 AM
  6. Can I Hide Shapes That Are Buttons???
    By JonesZoid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2012, 05:32 PM
  7. [SOLVED] Want to just Delete Command Buttons frm a Copied Sheet excluding ALL other Shapes ?
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-27-2012, 03:00 AM
  8. Code for a master command button to change the backcolor of multiple command buttons?
    By panttherm5 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2012, 10:11 PM

Tags for this Thread

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