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:
- Declare an array to store your brand names:
Formula:
Dim brands(1 To 160) As String
- Populate the array with your list of brand names:
Formula:
brands(1) = "Brand1"
brands(2) = "Brand2"
brands(3) = "Brand3"
'...
brands(160) = "Brand160"
- Use a loop to filter the data based on the brand names in the array:
Formula:
For i = 1 To 160
ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:=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:=1, Criteria1:=criteria1
ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:=criteria2
ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:=criteria3
'...
This code breaks up the filter criteria into smaller chunks, which can help avoid the "Too Many Line Continuations" error.