+ Reply to Thread
Results 1 to 3 of 3

Target range in macro is too long?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Target range in macro is too long?

    Hello,

    I have an Excel macro (Thank you forum users!) that will lock cells after data has been entered and saved. It works beautifully, but recently, I have created a spreadsheet where there are hundreds of cells that need to be protected after they have been populated. The problem is that the cells are non contiguous and when I try to type in the cell range, the line of code becomes too long and stops working. Is it possible to split this range into two or more lines of code? Or can I apply the same macro to the same Excel tab twice, with the first macro protecting the first 200 cells (for example) and the second macro protecting the last 200 cells? Thanks in advance!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,451

    Re: Target range in macro is too long?

    Post your code. It might be as simple as using underscore ( _ ) to break the line. Or you could define two or more ranges and then use Union to join them together.

    Regards, TMS
    Last edited by TMS; 02-17-2013 at 09:23 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-17-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Target range in macro is too long?

    Thanks for the reply! The specific line of code is:

    "ActiveSheet.Range("A1:B4,D1:E4,G1:H4,A6:B10,D6:E10,G6:H10").Select"

    For simplicity, I just wrote 6 cell ranges here, but in the spreadsheet that I am working on now, there are over 100.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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