Here is a tricky question.
I have an Excel file containing roughly 4000 articles in each of the 10 sheets within the workbook. I would like to keep only about 400 articles and the remaining 3600 articles should be removed.
All sheets within the workbook has the article ID in column A.
All sheets has headers on row 1-5.
The article ID can exist more than once in some of the sheets.
I want to list the 400 article ID's in the Visual Basic Script itself so that i don't have to create a separate sheet or column that contains the information.
Can someone please help me? I have tried so many scripts, but nothing seems to work...
In the example below I want to keep Article ID's 5 and 1 (and of course the headers). The remaining 5 rows should be removed
This is what i have tried:
Sub Delete()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 6
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "Y")
If Not IsError(.Value) Then
If InStr(.Value, 1) = 0 Or InStr(.Value, 5) = 0 Then .EntireRow.Delete
End If
End With
Next Lrow
End With
End Sub
But, I get two issues:
All rows are removed including the rows that I want to remove (1 and 5).
It only works on the open sheet and not the whole workbook.
Kind regards,
Peter