Looking to kick rows of data in Sheet A based off what cells in Sheet C say

rossross

New Member
Joined
Apr 11, 2022
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hi, i've got a code that works - kind of. It does run, and it runs at a good speed. Only problem is that it's not kicking the right rows...

High level explanation: I've got sheet A with all my data, it goes to sheet B to see what qualifier to use and then finds it in sheet C which ones have that qualifier.

Maybe the easiest thing to do is amend this since i know it does work (based off an almost identical code i'm running in another workbook). Maybe it's easier to scrap this and use something new...

and for the record, i don't know if my array is correct. I only have one column i'm looking at and one qualifier. And when you see "collett" in this text, that is a function that my head guy wrote that gets column letter. it works as intended.

VBA Code:
Sub disqualify()

Dim i As Long
Dim j As Long
Dim ne As Long
Dim ecol As Long
Dim erow As Long
Dim trow As Long
Dim sel As Worksheet
Dim arre(3, 3) As String
Dim nws As Worksheet

Set ip = ThisWorkbook.Worksheets("Inputs")
Set data = ThisWorkbook.Worksheets("Data")
Set sel = ThisWorkbook.Worksheets("Selector")

'dims are declared under option explicit at the top so not showing here

ne = 0

With ip
    ecol = .Range(.Range("endref")).Column
    erow = .Range(.Range("endref")).Row
    ecol = ecol + 1
    erow = erow + 6
' "endref" is named range
    For i = 0 To 2
       
        If Len(.Range("N" & (i + 2))) > 0 Then
        arre(i, 0) = .Range("N" & (i + 2))
        arre(i, 1) = .Range("O" & (i + 2))
        arre(i, 2) = ThisWorkbook.Worksheets("Selector").Range(arre(i, 0) & "1")
       
        With sel
            .Select
            .Range("A1").Select
            .Cells.Find(What:=arre(i, 2), After:=ActiveCell, LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False).Activate
        End With
       
        arre(i, 2) = collett(ActiveCell.Column)
        ne = ne + 1
       
        End If
    Next i
End With

With data
    For i = 8 To erow
        For j = 0 To (ne - 1)
            If Evaluate("'Selector'!" & arre(j, 2) & i & arre(j, 1)) Then
                .Range(collett(ecol) & i) = arre(j, 2) & arre(j, 1)
                Exit For
            End If
        Next j
    Next i
   
    .Range(collett(ecol) & 7) = "Flag"
    Call formatcols(ecol, 8, erow, "Text", "Tape")
    .Columns(collett(ecol) & ":" & collett(ecol)).ColumnWidth = 17
   
    'land page
    .Copy After:=Sheets(Sheets.Count)
    Sheets("Data (2)").Name = "Eligible"
End With

Set nws = ThisWorkbook.Worksheets("Eligible")

With nws
    .Select
    .Range("A7:" & collett(ecol) & erow).ClearContents
    .Range("A7").Select
End With

With data
    .Select
    .Range("$A$7:$" & collett(ecol) & "$" & erow).AutoFilter field:=ecol, Criteria1:="="
    .Range("A7").Select
    .Range(Selection, Selection.End(xlToRight)).Select
    .Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
End With

With nws
    .Select
    .Range("A7").Select
    .Paste
    .Range("A7").Select
    Selection.End(xlDown).Select
    trow = Selection.Row
    .Range("A" & (trow + 1)).Select
    .Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete
    .Range("A7").Select
End With
              
With data
    .Select
    Selection.AutoFilter
    .Range("A7").Select
End With

With nws
    .Select
    .Range("A7").Select
End With

End Sub


like i said, it's running, correctly identifying which sheets and columns and stipulation to use but not selecting the right ones. Oddly, the count is correct... just not the correct ones. also when stepping through the code, on the third loop, it no longer shows what it's checking and shows "subscript out of range" and no value. maybe 2 is what i need my array to show? again, not sure how that works.

EDIT: it's actually on the second loop where it starts to show the subscript out of range message while hovering over the code
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top