+ Reply to Thread
Results 1 to 7 of 7

Multiple With Statements

  1. #1
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Multiple With Statements

    I'm trying to condense down a list of With statements I have written in a module into a much shorter piece of code. The purpose of the code is to enable/disable the user's ability to select cells and scroll.

    This is the code to disable cell selection and scrolling:

    Please Login or Register  to view this content.
    And this is the code to enable cell selection/scrolling:

    Please Login or Register  to view this content.
    So what's the best way of condensing both sets of code? I know it's not as simple as just listing the sheet names at the top of a With statement.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Multiple With Statements

    Hi,

    You can refactor the repeated code into its own routine
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Re: Multiple With Statements

    Quote Originally Posted by xlnitwit View Post
    Hi,

    You can refactor the repeated code into its own routine
    Please Login or Register  to view this content.
    Thanks for your response. However, when I run the top half of the code that disables the cell selection, I get an error message saying 'Compile error: Sub or Function not defined'. It highlights the 'EnableSelection' part.

  4. #4
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Multiple With Statements

    I think that the sub is missing a name at the top

    so

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Re: Multiple With Statements

    Quote Originally Posted by davsth View Post
    I think that the sub is missing a name at the top

    so

    Please Login or Register  to view this content.
    The thing is, this code is part of one Sub. The purpose is to allow for quick switching between admin view and user view in the workbook. This is the whole code. Let's see if we can integrate a solution to fit into this...

    Please Login or Register  to view this content.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Multiple With Statements

    This part is a separate routine and should be outside (either before or after, or in a different module to) the original routine
    Please Login or Register  to view this content.
    then you need only replace the relevant sections in your code with the calls to this routine as I posted.

  7. #7
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Re: Multiple With Statements

    Quote Originally Posted by xlnitwit View Post
    This part is a separate routine and should be outside (either before or after, or in a different module to) the original routine
    Please Login or Register  to view this content.
    then you need only replace the relevant sections in your code with the calls to this routine as I posted.
    That works great — thanks a lot. The only problem I'm having is when I run the code, it locks the checkboxes, radio buttons and spinners in user mode — meaning they can't be clicked on without a dialog box appearing.

    What can I add to the code to make sure that these objects are kept unlocked?

+ 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] Nested if statements containing multiple and statements
    By John M. in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-22-2014, 11:48 PM
  2. Formula with multiple IF statements and IF AND statements
    By lottidotti in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-14-2013, 08:03 AM
  3. Replies: 3
    Last Post: 07-25-2013, 08:25 AM
  4. [SOLVED] Formula Problem with Multiple IF / AND Statements and Multiple outcome?
    By JONBOY666 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-22-2013, 01:32 PM
  5. [SOLVED] Syntax for formula that uses multiple conditions inside of multiple IF statements
    By njmiller31 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-02-2013, 11:55 AM
  6. Multiple nested IF statements and AND statements
    By TonyGetz in forum Excel General
    Replies: 2
    Last Post: 12-14-2010, 03:07 AM
  7. Replies: 12
    Last Post: 05-15-2009, 08: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