JohanGduToit
Board Regular
- Joined
- Nov 12, 2021
- Messages
- 89
- Office Version
- 365
- 2016
- Platform
- Windows
Afternoon All,
I am attempting to delete entire rows across multiple worksheets based on text value criteria contained in Column B (on every worksheet). So as the code cycle through each worksheet, it should find rows where Column B values are either "*soh*" or "*IT NETT*" and delete those rows on every worksheet.
My code below looks for a specific worksheet named "Updated Allocation List" and if it exist it gets deleted. The top 4 rows are also deleted from the other worksheets.
The section between "Start Filter and Delete" and "End Filter and Delete" comments works; but only on the last worksheet; it does not delete the relevant rows from any of the other worksheets. I am also not sure how to specify the criteria to be both "*soh*" and "*IT NETT*".
Please assist? Thank you!!
I am attempting to delete entire rows across multiple worksheets based on text value criteria contained in Column B (on every worksheet). So as the code cycle through each worksheet, it should find rows where Column B values are either "*soh*" or "*IT NETT*" and delete those rows on every worksheet.
My code below looks for a specific worksheet named "Updated Allocation List" and if it exist it gets deleted. The top 4 rows are also deleted from the other worksheets.
The section between "Start Filter and Delete" and "End Filter and Delete" comments works; but only on the last worksheet; it does not delete the relevant rows from any of the other worksheets. I am also not sure how to specify the criteria to be both "*soh*" and "*IT NETT*".
Please assist? Thank you!!
VBA Code:
Public Sub FormatMarkham01(sFile As String)
'Delete Worksheet <Updated Allocation List> if sheet exist, Delete Rows 1 to 4 and Delete all Rows containing specified text.
Dim xlApp As Object
Dim xlSheet As Object
Dim I As Long
Application.SetOption "Show Status Bar", True
vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting Markham Sales File (Stage 1)... Please wait.")
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
With xlApp
.Application.ScreenUpdating = False
.Application.DisplayAlerts = False
For I = .Application.Sheets.Count To 1 Step -1
If .Application.Sheets(I).Name = "Updated Allocation List" Then
.Application.Sheets(I).Delete
Else
.Application.Sheets(I).Rows(1).Resize(4).Delete
[B]'Start Filter and Delete
'.Application.AutoFilterMode = False
With .Application.Range("B1", .Application.Range("B" & .Application.Rows.Count).End(xlUp))
.AutoFilter 1, "*soh*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
'End Filter and Delete[/B]
End If
Next
.Application.ScreenUpdating = True
.Application.Sheets(1).Select
.Application.Range("A1").Select
.Application.ActiveWorkbook.Save
.Application.ActiveWorkbook.Close
.Quit
End With
vStatusBar = SysCmd(acSysCmdClearStatus)
Set xlSheet = Nothing
Set xlApp = Nothing
End Sub