+ Reply to Thread
Results 1 to 13 of 13

Limit replication of coding inside spreadsheet

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    8

    Limit replication of coding inside spreadsheet

    Hi all, I'll start with the good news, in that I have managed to get all the VBA to work just how I want it to. My problem is that now every tie I need to edit the sheet or moving things round/add rows etc I need to make onerous modifications to the code!!

    Basically I wasn't smart enough when I set up my coding at the start.

    I have 30 checkboxes which control different rows. They are all sequential rows or groups of rows but no consistency in the number of rows in each group. I.e. 1-6 in one group, 7-10 in another 11-25 in the next etc.

    I have used the following code to achieve what I was hoping for on my spread sheet:

    Please Login or Register  to view this content.
    As you can see each sub has the row numbers written in twice, which need to be edited twice every time something changes on my sheet.

    Is there a way that I can pre-define the groups of rows I want in one place, then get the code of each of the 30 checkboxes to refer to that?

    I'm confident that it can be done, just not sure what the best way of doing it is? I do appreciate that I'll have to modify the code of each of the 30 checkboxes, but hopefully after this any modifications will be simpler!!!!


    Most appreciated of any advice or help that can be offered
    Regards

    Paul
    Last edited by alansidman; 09-15-2014 at 12:52 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Limit replication of coding inside spreadsheet

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Limit replication of coding inside spreadsheet

    Try this:

    Please Login or Register  to view this content.
    or this:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-10-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    8

    Re: Limit replication of coding inside spreadsheet

    Firstly my apologies and thank you.

    So if I modify the code thusly
    Please Login or Register  to view this content.
    Can I collated all the
    Please Login or Register  to view this content.
    in one place, outside of each of the 30 Private Sub routines.

    Is that possible?

    Paul

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Limit replication of coding inside spreadsheet

    Set the ranges as Public outside the module. No need to set them inside the module.

    Look at this link for an explanation.

    http://www.ozgrid.com/forum/showthread.php?t=95488

  6. #6
    Registered User
    Join Date
    09-10-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    8

    Re: Limit replication of coding inside spreadsheet

    I'm afraid we are hurtling towards my limit of VBA understanding and it frustrates me that I know this is barely elementary!!!

    I have typed in the following code, but I get a complied error: invalid outside procedure. In particular it highlight the 'set' function. Is it obvious what I'm doing wrong??

    Please Login or Register  to view this content.
    Regards
    P

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Limit replication of coding inside spreadsheet

    You have set the range without a reference to any column.

    Try changing it up to look like this:

    Please Login or Register  to view this content.
    It will not matter that you indicate a column since you are selecting the entire row to hide

  8. #8
    Registered User
    Join Date
    09-10-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    8

    Re: Limit replication of coding inside spreadsheet

    I think that I'm still doing something wrong! I keep getting a complier error: Invalid outside procedure

    this is the code that I have

    Please Login or Register  to view this content.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Limit replication of coding inside spreadsheet

    Let me do some testing and I will get back to you.

  10. #10
    Registered User
    Join Date
    09-10-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    8

    Re: Limit replication of coding inside spreadsheet

    Thank you that would be great

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Limit replication of coding inside spreadsheet

    Ok. My bad. You can't set the variable range as a constant. Instead here is a work around

    Please Login or Register  to view this content.
    You will have to define (Dim) each of your ranges above the function
    Create a Getrng1, Getrng2, etc for each of your ranges

    Then in your Sub you can set each of the ranges so that you will only have to reset the GetrngX when you need to make a range change and not the Sub itself.
    Last edited by alansidman; 09-15-2014 at 04:41 PM.

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

    Re: Limit replication of coding inside spreadsheet

    Paul

    How are the groups defined/identified?

    Also, where are the checkboxes in location to the groups?
    If posting code please use code tags, see here.

  13. #13
    Registered User
    Join Date
    09-10-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    8

    Re: Limit replication of coding inside spreadsheet

    Hi alansidman,

    so following your suggestion I now have the following code:

    Please Login or Register  to view this content.
    Unfortunately this doesn't work either. I get a runtime error '438' error. Debugging highlighst the follwing line: Sheets("Sheet1").rng1.EntireRow.Hidden = True

    @Norie
    the groups I want to define at the rows which are controlled by the checkboxes. Everything I'm trying to do is located on Sheet 1 of hte spreadsheet. I trust this answers your question?

    Regards

    Paul

+ 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] moving my cursor inside the same spreadsheet
    By DixieDoll11 in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 02-06-2014, 04:53 PM
  2. [SOLVED] Generate a spreadsheet, which contains code inside?
    By kaligad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2013, 05:19 AM
  3. Replies: 17
    Last Post: 10-22-2010, 04:20 AM
  4. coding to add values until a certain limit
    By dan2010 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-16-2010, 05:18 AM
  5. [SOLVED] Looking for inside sale compensation spreadsheet
    By cgphx in forum Excel General
    Replies: 0
    Last Post: 03-23-2005, 01:06 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