+ Reply to Thread
Results 1 to 6 of 6

[SOLVED] code exceeds max. # of characters per line

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    [SOLVED] code exceeds max. # of characters per line

    How do i start a new line of code if i exceed the max. # of characters?

    here is my code: i did to continue the Range to a new line.

    Sub ClearForm()
        ActiveSheet.Unprotect Password:="pec123"
        Range("D1:G5,C7:AC8,D11:D14,D22:D25,D33:D36,D44:D47,D55:D58,D66:D69,D77:D80,D88:D91,D99:D102,D110:D113,D121:D124,D132:D135,D143:D146,D154:D157,D165:D168,H11:Z171,AB17,AB28,AB39,AB50,AB61,AB72,AB83,AB94,AB105,AB116,AB127,AB138,AB149,AB160,AB171").Select
        Selection.ClearContents
        ActiveSheet.Protect Password:="pec123", DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowFiltering:=True
    End Sub
    Last edited by adamheon; 02-19-2014 at 11:36 AM.

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: code exceeds max. # of characters per line

    If this range is static you could create a named range and use that....
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: code exceeds max. # of characters per line

    Another solution something like

    Sub ClearForm()
        ActiveSheet.Unprotect Password:="pec123"
        Union(Range("D1:G5,C7:AC8,D11:D14,D22:D25,D33:D36,D44:D47,D55:D58,D66:D69,D77:D80,D88:D91,D99:D102,D110:D113,D121:D124,D132:D135,D143:D146,D154:D157,D165:D168"), _
        Range("H11:Z171,AB17,AB28,AB39,AB50,AB61,AB72,AB83,AB94,AB105,AB116,AB127,AB138,AB149,AB160,AB171")).ClearContents
        ActiveSheet.Protect Password:="pec123", DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowFiltering:=True
    End Sub
    or

    Sub ClearForm()
        ActiveSheet.Unprotect Password:="pec123"
        Range("D1:G5,C7:AC8,D11:D14,D22:D25,D33:D36,D44:D47,D55:D58,D66:D69,D77:D80,D88:D91,D99:D102,D110:D113,D121:D124,D132:D135,D143:D146,D154:D157,D165:D168").ClearContents
        Range("H11:Z171,AB17,AB28,AB39,AB50,AB61,AB72,AB83,AB94,AB105,AB116,AB127,AB138,AB149,AB160,AB171").ClearContents
        ActiveSheet.Protect Password:="pec123", DrawingObjects:=True, Contents:=True, Scenarios:=True _
                          , AllowFiltering:=True
    End Sub
    Note that you don't have to select the range
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    Re: code exceeds max. # of characters per line

    I'm sorry I added the wrong code....could you show how it should look with this code?

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("H12:Z12,H16:Z16,H23:Z23,H27:Z27,H34:Z34,H38:Z38,H45:Z45,H49:Z49,H56:Z56,H60:Z60,H67:Z67,H71:Z71,H78:Z78,H82:Z82,H89:Z89,H93:Z93,H100:Z100,H104:Z104,H111:Z111,H115:Z115,H122:Z122,H126:Z126,H133:Z133,H137:Z137,H144:Z144,H148:Z148,H155:Z155,H159:Z159")) Is Nothing Then Exit Sub
    Dim r As Range
    Set r = Range("AO1:AO8").Find(Target)
    If r Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Target.Value = r(1, 2)
    Application.EnableEvents = True
    End Sub

  5. #5
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: code exceeds max. # of characters per line

    Something like this

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub
        If Intersect(Target, _
                     Union(Range("H12:Z12,H16:Z16,H23:Z23,H27:Z27,H34:Z34,H38:Z38,H45:Z45,H49:Z49,H56:Z56,H60:Z60"), _
                           Range("H67:Z67,H71:Z71,H78:Z78,H82:Z82,H89:Z89,H93:Z93,H100:Z100,H104:Z104,H111:Z111,H115:Z115"), _
                           Range("H122:Z122,H126:Z126,H133:Z133,H137:Z137,H144:Z144,H148:Z148,H155:Z155,H159:Z159"))) _
                           Is Nothing Then
            Exit Sub
        End If
        Dim r As Range
        Set r = Range("AO1:AO8").Find(Target)
        If r Is Nothing Then Exit Sub
        Application.EnableEvents = False
        Target.Value = r(1, 2)
        Application.EnableEvents = True
    End Sub

    However my personal preference would be to declare a variable of type range that will hold reference to the range in question

  6. #6
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    Re: code exceeds max. # of characters per line

    Thank you!

+ 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. Replies: 1
    Last Post: 08-30-2013, 04:56 PM
  2. importing data that exceeds 255 characters
    By dmac_59 in forum Excel General
    Replies: 0
    Last Post: 10-31-2007, 06:22 PM
  3. Calculating a formula that exceeds 1,000 characters
    By w1nter11 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-14-2006, 09:25 AM
  4. Delete A Word That Exceeds X Number Of Characters
    By brazen234 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-31-2005, 12:40 PM
  5. [SOLVED] Footers in which number of characters exceeds 255
    By DRK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-09-2005, 01:05 PM

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