jassybun
Member
the code below works great with deleting columns not needed - but I also want to delete rows, and keep only ones where the Work Activity equals "76", "77", "82" or "85"
Instructions: https://chandoo.org/forum/threads/posting-a-sample-workbook.451/
Instructions: https://chandoo.org/forum/threads/posting-a-sample-workbook.451/
Code:
Sub DeleteColumnsRows()
Dim Sht2 As Worksheet, Sht3 As Worksheet
Dim Dict As Object, Cell As Range
Dim Dict2 As Object, Cell2 As Range
Dim RngToDelete As Range
Set Sht2 = ThisWorkbook.Sheets("Sheet1") 'Modify accordingly.
Set Sht3 = ThisWorkbook.Sheets("Sheet2") 'Modify accordingly.
Application.ScreenUpdating = False
With Sht2
For Each Cell In .Rows(1).Cells
If InStr(1, Cell.Value, "PPE Date") = 0 And InStr(1, Cell.Value, "Work Center") = 0 And InStr(1, Cell.Value, "Name") = 0 And InStr(1, Cell.Value, "Work Activity") = 0 And InStr(1, Cell.Value, "Operation") = 0 Then
If Not RngToDelete Is Nothing Then
Set RngToDelete = Union(RngToDelete, .Columns(Cell.Column))
Else
Set RngToDelete = .Columns(Cell.Column)
End If
End If
Next Cell
RngToDelete.Delete
Application.ScreenUpdating = True
End With
End Sub
Last edited by a moderator: