ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Too Many Line continuations (https://www.excelbanter.com/excel-discussion-misc-queries/202445-too-many-line-continuations.html)

Gmata

Too Many Line continuations
 
I am trying to create a macro to filter about 160 brand names of 300, i
started recording a macro and then using filter, i checked all the brand
names i wanted, the problem is that when i finished i got the error msg " Too
Many Line Continuations" what can i do to create a macro to filter only those
160 or so brands?

Thanks

ExcelBanter AI

Answer: Too Many Line continuations
 
The "Too Many Line Continuations" error message usually occurs when there are too many line breaks in your code. This can happen when you have a long list of items that you are trying to filter.

One way to avoid this error is to use an array to store your list of brand names. Here's an example of how you can modify your code to use an array:
  1. Declare an array to store your brand names:
    Formula:

    Dim brands(1 To 160) As String 

  2. Populate the array with your list of brand names:
    Formula:

    brands(1) = "Brand1"
    brands(2) = "Brand2"
    brands(3) = "Brand3"
    '...
    brands(160) = "Brand160" 

  3. Use a loop to filter the data based on the brand names in the array:
    Formula:

    For 1 To 160
        ActiveSheet
    .Range("A1").AutoFilter Field:=1Criteria1:=brands(i)
    Next i 


This code will filter the data based on each brand name in the array, one at a time.

Alternatively, you can also try breaking up your code into smaller chunks by using variables to store parts of your filter criteria. This can help reduce the number of line continuations in your code. For example:

Formula:

Dim criteria1 As String
Dim criteria2 
As String
Dim criteria3 
As String
'...

criteria1 = "Brand1" & "," & "Brand2" & "," & "Brand3" & "," '
...
criteria2 "Brand21" "," "Brand22" "," "Brand23" "," '...
criteria3 = "Brand41" & "," & "Brand42" & "," & "Brand43" & "," '
...

ActiveSheet.Range("A1").AutoFilter Field:=1Criteria1:=criteria1
ActiveSheet
.Range("A1").AutoFilter Field:=1Criteria1:=criteria2
ActiveSheet
.Range("A1").AutoFilter Field:=1Criteria1:=criteria3
'... 

This code breaks up the filter criteria into smaller chunks, which can help avoid the "Too Many Line Continuations" error.

Rick Rothstein

Too Many Line continuations
 
Uh... don't use so many line continuations maybe? In case you are not aware
of what that message means... it occurs when you take a long line of text an
split it up on multiple lines using a space followed by an underline to keep
the links linked together. For example...

SomeTextVariable = "Line one which goes on for awhile and " & _
"then continues on, but one line lower"

If I recall correctly, there are a maximum of 25 line continuations that can
be used on a single code statement... so just don't break it apart so
often... or see if you can split the multiline statement you are trying to
construct into more than one statement, each of which can have a maximum of
25 line continuations.

--
Rick (MVP - Excel)


"Gmata" wrote in message
...
I am trying to create a macro to filter about 160 brand names of 300, i
started recording a macro and then using filter, i checked all the brand
names i wanted, the problem is that when i finished i got the error msg "
Too
Many Line Continuations" what can i do to create a macro to filter only
those
160 or so brands?

Thanks



Bob Phillips[_3_]

Too Many Line continuations
 
.... or better still, put the 160 into a worksheet table and compare against
that.

--
__________________________________
HTH

Bob

"Rick Rothstein" wrote in message
...
Uh... don't use so many line continuations maybe? In case you are not
aware of what that message means... it occurs when you take a long line of
text an split it up on multiple lines using a space followed by an
underline to keep the links linked together. For example...

SomeTextVariable = "Line one which goes on for awhile and " & _
"then continues on, but one line lower"

If I recall correctly, there are a maximum of 25 line continuations that
can be used on a single code statement... so just don't break it apart so
often... or see if you can split the multiline statement you are trying to
construct into more than one statement, each of which can have a maximum
of 25 line continuations.

--
Rick (MVP - Excel)


"Gmata" wrote in message
...
I am trying to create a macro to filter about 160 brand names of 300, i
started recording a macro and then using filter, i checked all the brand
names i wanted, the problem is that when i finished i got the error msg "
Too
Many Line Continuations" what can i do to create a macro to filter only
those
160 or so brands?

Thanks






All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com