Hello, I've been using this code to delete everything on a spreadsheet that doesnt match a customer number in a column. it's been workign fine up until today, when i am suddently getting a type mismatch error. I am looping through a list of items on a spreadsheet and pulling the values for the tab to inspect, the ID type to use, the column that the ID is in, and the row where the data starts after a header.
It appears to crash after all the rows that do not match the ID have been deleted, and sometimes crashes on the first tab (NavEOB) and other times crashed on the second tab (File Frequency) but never makes it further than that. Is there somethign i need to chance to make this work consistently? or a better way to write this all together?
This is where its crashing
It appears to crash after all the rows that do not match the ID have been deleted, and sometimes crashes on the first tab (NavEOB) and other times crashed on the second tab (File Frequency) but never makes it further than that. Is there somethign i need to chance to make this work consistently? or a better way to write this all together?
This is where its crashing
Code:
Sub Isolation()
Dim Tabs As String, Filter As String, col As String, row As Long
Dim lr As Long, r As Long
lr = Sheets("Links").UsedRange.Rows.Count
Sheets("Control").Range("A18:H40").Delete
Sheets("Control").Range("C19").Value = "Tab"
Sheets("Control").Range("F19").Value = "Result"
Sheets("Control").Range("A19:f19").Font.Bold = True
For r = 2 To lr
it = r + 18
Tabs = Sheets("Links").Range("B" & r).Value
Filter = Sheets("Links").Range("c" & r).Value
col = Sheets("Links").Range("f" & r).Value
row = Sheets("Links").Range("g" & r).Value
x = Del_Fast(Tabs, Filter, col, row)
x = report(Tabs, Filter, col, row)
Next r
Sheets("Control").Select
End Sub
Function Del_Fast(t As String, f As String, c As String, r As Long)
'cuts the NAVEOB list down to the necessary records
Dim a As Variant, b As Variant
Dim nc As Long, i As Long, k As Long, id As Long
If f = "PH Number" Then
id = Sheets("Control").Range("PH").Value
Else
id = Sheets("Control").Range("PSU").Value
End If
Sheets(t).Select
nc = Sheets(t).Cells.Find(What:="*", LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
a = Sheets(t).Range(c & r, Sheets(t).Range(c & Rows.Count).End(xlUp)).Value
ReDim b(1 To UBound(a), 1 To 1)
For i = 1 To UBound(a)
If Not a(i, 1) Like "*" & id Then
b(i, 1) = 1
k = k + 1
End If
Next i
If k > 0 Then
'Application.ScreenUpdating = False
With Sheets(t).Range("A" & r).Resize(UBound(a), nc)
.Columns(nc).Value = b
.Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlNo
.Resize(k).EntireRow.Delete
End With
'Application.ScreenUpdating = True
End If
End Function
[\code]