+ Reply to Thread
Results 1 to 10 of 10

How to combine locked cells and forced uppercase separately using range?

  1. #1
    Registered User
    Join Date
    05-26-2021
    Location
    Hong Kong
    MS-Off Ver
    MS 365
    Posts
    13

    How to combine locked cells and forced uppercase separately using range?

    Hi, I am new to VBA and require some help.

    I am able to lock cells for a certain range (below):

    Please Login or Register  to view this content.
    And also make certain cells to force uppercase on them (below):

    Please Login or Register  to view this content.
    And I learnt that there cannot be duplicates of Worksheet_Change but i am having difficulties on how to combine them together. Kindly advise on how to combine them both.
    Have attached the excel document on what i have done also.
    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,414

    Re: How to combine locked cells and forced uppercase separately using range?

    Untested but this should correctly combine your two Change event procedures into a single one.
    Please Login or Register  to view this content.
    Note: I used your code exactly as you wrote but have a couple of comments about it. First, the variable name I highlighted in red is not Dim'med in your code and no value has been assigned to it before you used it in your If..Then test. Second, as written, if a large selection of cells intersects with either of the ranges you are testing for, your code will process every cell within that large selection. This would be particularly troublesome if you attempted to select all the cells on the sheet in order to clear them... it would take a long, long, long, long time before you would be able to regain control of your computer. If you are only changing one cell at a time, you should test (at the beginning of your code) that Target.Count and if it is greater than 1, then Exit Sub.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: How to combine locked cells and forced uppercase separately using range?

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    05-26-2021
    Location
    Hong Kong
    MS-Off Ver
    MS 365
    Posts
    13

    Re: How to combine locked cells and forced uppercase separately using range?

    Quote Originally Posted by Rick Rothstein View Post
    Untested but this should correctly combine your two Change event procedures into a single one.
    Please Login or Register  to view this content.
    Note: I used your code exactly as you wrote but have a couple of comments about it. First, the variable name I highlighted in red is not Dim'med in your code and no value has been assigned to it before you used it in your If..Then test. Second, as written, if a large selection of cells intersects with either of the ranges you are testing for, your code will process every cell within that large selection. This would be particularly troublesome if you attempted to select all the cells on the sheet in order to clear them... it would take a long, long, long, long time before you would be able to regain control of your computer. If you are only changing one cell at a time, you should test (at the beginning of your code) that Target.Count and if it is greater than 1, then Exit Sub.
    Hi Rick, i tried using the code and it returned an error (below) with the portion highlighted:
    Run-time error '91': Object variable or With block variable not set
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-26-2021
    Location
    Hong Kong
    MS-Off Ver
    MS 365
    Posts
    13

    Re: How to combine locked cells and forced uppercase separately using range?

    Quote Originally Posted by sintek View Post
    Please Login or Register  to view this content.
    Hi sintek, where do i put the script as mentioned in your reply?

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,414

    Re: How to combine locked cells and forced uppercase separately using range?

    Quote Originally Posted by Riki55 View Post
    Hi Rick, i tried using the code and it returned an error (below) with the portion highlighted:
    Run-time error '91': Object variable or With block variable not set
    Please Login or Register  to view this content.
    Looks like I screwed that up somewhat. See if this works for you...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-26-2021
    Location
    Hong Kong
    MS-Off Ver
    MS 365
    Posts
    13

    Re: How to combine locked cells and forced uppercase separately using range?

    Quote Originally Posted by Rick Rothstein View Post
    Looks like I screwed that up somewhat. See if this works for you...
    Please Login or Register  to view this content.
    Hi Rick, thanks for your reply. It is working now but somehow the forcing uppercase for the specific range is not working?

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: How to combine locked cells and forced uppercase separately using range?

    Error in your code snippet ... 0 to be used ... not O
    Please Login or Register  to view this content.

    As Rick pointed out earlier...Were is mStr declared and where is its value assigned..
    Hi sintek, where do i put the script as mentioned in your reply?
    Please Login or Register  to view this content.
    Last edited by sintek; 05-28-2021 at 03:47 AM.

  9. #9
    Registered User
    Join Date
    05-26-2021
    Location
    Hong Kong
    MS-Off Ver
    MS 365
    Posts
    13

    Re: How to combine locked cells and forced uppercase separately using range?

    Quote Originally Posted by sintek View Post
    Error in your code snippet ... 0 to be used ... not O
    Please Login or Register  to view this content.

    As Rick pointed out earlier...Were is mStr declared and where is its value assigned..

    Please Login or Register  to view this content.
    Hi sintek, you are right on the 0 and not O. I didn't notice that.
    Thank you and also to Rick. It is working perfectly now!

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: How to combine locked cells and forced uppercase separately using range?

    For future threads...No need to quote entire posts as this just clutters the thread...If you want to reference something specifically, just quote that small snippet...

    So just out of interest...Were is mStr declared and where is its value assigned..

    And...thanks for rep +

+ 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] Forced Calculation of All Cells
    By ffffloyd in forum Excel General
    Replies: 10
    Last Post: 11-06-2014, 08:36 PM
  2. Copy and paste locked cells, and have pasted cells retain LOCKED status.
    By stratloveslenny in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2014, 03:05 PM
  3. Replies: 3
    Last Post: 04-12-2014, 04:47 AM
  4. Unlock only a range of cells on a locked sheet?
    By Margate in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 09:32 AM
  5. Getting the Min for Moving Range with Locked Cells
    By RoxannaBannana in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-25-2013, 04:01 PM
  6. Forced input into cells
    By MattGriff in forum Excel General
    Replies: 1
    Last Post: 03-01-2011, 12:00 PM
  7. forced selection of a merged cell range otherwise no action from commandbutton
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2010, 03:23 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