Sub me1158548()
Dim ws As Worksheet, f As Range
For Each ws In Sheets
Set f = ws.Cells.Find("Work Order", lookat:=xlWhole)
If Not f Is Nothing Then
If f.Row > 1 Then ws.Cells(1).Resize(f.Row - 1).EntireRow.Delete
End If
Next
End Sub
Thank you, it worked. Could you please show the code to delete all rows below "Work Order" and all columns to the right and left of "Work Order"Please test on a copy of your workbook first.
VBA Code:Sub me1158548() Dim ws As Worksheet, f As Range For Each ws In Sheets Set f = ws.Cells.Find("Work Order", lookat:=xlWhole) If Not f Is Nothing Then If f.Row > 1 Then ws.Cells(1).Resize(f.Row - 1).EntireRow.Delete End If Next End Sub
ws.Cells(f.Row + 1).Resize(Rows.Count - f.Row).EntireRow.Delete
ws.Columns(f.Column + 1).Resize(Columns.Count - f.Column).Delete
If f.Column > 1 Then ws.Columns(f.Column - 1).Resize(f.Column - 1).Delete
For deleting rows below "work order", I used the following code but it did not work. Am I doing it wrong :All rows below:
All columns to right:VBA Code:ws.Cells(f.Row + 1).Resize(Rows.Count - f.Row).EntireRow.Delete
All columns to left:VBA Code:ws.Columns(f.Column + 1).Resize(Columns.Count - f.Column).Delete
VBA Code:If f.Column > 1 Then ws.Columns(f.Column - 1).Resize(f.Column - 1).Delete
Did you get any errors? or what happened?but it did not work
I do not get any errors. It deletes everything in the worksheet. Expected result will be to delete only rows below "Work Order"Did you get any errors? or what happened?
Apologies for that, try this:It deletes everything in the worksheet
Sub me1158548()
Dim ws As Worksheet, f As Range
For Each ws In Sheets
Set f = ws.Cells.Find("Work Order", lookat:=xlWhole)
If Not f Is Nothing Then
If f.Row > 1 Then ws.Cells(f.Row + 1, 1).Resize(Rows.Count - f.Row).EntireRow.Delete
End If
Next
End Sub
It work now, thank youApologies for that, try this:
.Cells was missing a ", 1"VBA Code:Sub me1158548() Dim ws As Worksheet, f As Range For Each ws In Sheets Set f = ws.Cells.Find("Work Order", lookat:=xlWhole) If Not f Is Nothing Then If f.Row > 1 Then ws.Cells(f.Row + 1, 1).Resize(Rows.Count - f.Row).EntireRow.Delete End If Next End Sub
Could you also provide the VBA if I want to delete the column which has the word "Work Order" in it.It work now, thank you