moorecurls
New Member
- Joined
- Oct 28, 2022
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
I have an array that I need to load based on two different filters and then copy data to a new sheet. I have used code from a prior post "Extract some rows to a new sorted list" but need to add an extra filter. I also am getting an error 2015 on the aRws which is not allowing the array to load on the below code:
Sub DamageArray()
Dim i As Long, j As Long, k As Long, Cols As Long, LastRow As Long, rws As Long
Dim a As Variant, b As Variant, aRws As Variant, aCols As Variant
'First actual data row in 'Sheet1'
Const FirstRow As Long = 1
'Columns of Interest in 'Sheet1', in the order I want is AY BF BG BH BI BK AU AW
Const ColsOfInterest As String = "51 58 59 60 61 63 47 49"
'Value you want to filter on
Const filterVal As String = "FL*" 'this filter needs to be on colsOfInterest 51 or AY
'Const filterVal As String = "Junk*" ''this filter needs to be on colsOfInterest 58 or BF -- this is the second that I need to filter
'Make an array of column numbers for data area
aCols = Split(ColsOfInterest)
'Number of columns in result
Cols = UBound(aCols)
With Sheets("Sheet1")
'Find last row in Index column
LastRow = .Cells(.Rows.Count, CLng(aCols(Cols))).End(xlUp).Row
'Make an array of row numbers for data area. ie 10, 11, 12, ..
aRws = Evaluate("row(" & FirstRow & ":" & LastRow & ")") '''''this is where I'm getting the 2015 error
'Read all data rows, but only the cols of interest into an array
a = Application.Index(.Columns("A:BK"), aRws, aCols)
End With
'Calculate number of data rows
rws = LastRow - FirstRow + 1
'Set up b as an array to receive results
ReDim b(1 To rws, 1 To Cols)
'Loop through rows and put ones that have correct Index value into array b
For i = 1 To rws
If a(i, 1) = filterVal Then
k = k + 1
For j = 1 To Cols
b(k, j) = a(i, j)
Next j
End If
Next i
'Put results into 'FF' sheet '''I don't need to sort I just need the array results in the same ColsOfInterest "51 58 59 60 61 63 47 49" as fields
With Sheets("SheetFF").Range("A1").Resize(k, Cols)
.Value = b
.Offset(RowsToKeep).ClearContents
End With
End Sub
Any assistance to fix the 2015 error and add a second filter that would be wonderful. Thanks so much.
Sub DamageArray()
Dim i As Long, j As Long, k As Long, Cols As Long, LastRow As Long, rws As Long
Dim a As Variant, b As Variant, aRws As Variant, aCols As Variant
'First actual data row in 'Sheet1'
Const FirstRow As Long = 1
'Columns of Interest in 'Sheet1', in the order I want is AY BF BG BH BI BK AU AW
Const ColsOfInterest As String = "51 58 59 60 61 63 47 49"
'Value you want to filter on
Const filterVal As String = "FL*" 'this filter needs to be on colsOfInterest 51 or AY
'Const filterVal As String = "Junk*" ''this filter needs to be on colsOfInterest 58 or BF -- this is the second that I need to filter
'Make an array of column numbers for data area
aCols = Split(ColsOfInterest)
'Number of columns in result
Cols = UBound(aCols)
With Sheets("Sheet1")
'Find last row in Index column
LastRow = .Cells(.Rows.Count, CLng(aCols(Cols))).End(xlUp).Row
'Make an array of row numbers for data area. ie 10, 11, 12, ..
aRws = Evaluate("row(" & FirstRow & ":" & LastRow & ")") '''''this is where I'm getting the 2015 error
'Read all data rows, but only the cols of interest into an array
a = Application.Index(.Columns("A:BK"), aRws, aCols)
End With
'Calculate number of data rows
rws = LastRow - FirstRow + 1
'Set up b as an array to receive results
ReDim b(1 To rws, 1 To Cols)
'Loop through rows and put ones that have correct Index value into array b
For i = 1 To rws
If a(i, 1) = filterVal Then
k = k + 1
For j = 1 To Cols
b(k, j) = a(i, j)
Next j
End If
Next i
'Put results into 'FF' sheet '''I don't need to sort I just need the array results in the same ColsOfInterest "51 58 59 60 61 63 47 49" as fields
With Sheets("SheetFF").Range("A1").Resize(k, Cols)
.Value = b
.Offset(RowsToKeep).ClearContents
End With
End Sub
Any assistance to fix the 2015 error and add a second filter that would be wonderful. Thanks so much.