Hello, I am trying to write a macro to delete all rows below cell with "x" in it, and all columns right of the cell with "y" in it. Any suggestions? See attached, thanks!!
Hello, I am trying to write a macro to delete all rows below cell with "x" in it, and all columns right of the cell with "y" in it. Any suggestions? See attached, thanks!!
Try:![]()
Sub DeleteRowsColumns() Application.ScreenUpdating = False Dim LastRow As Long LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row Dim lColumn As Long lColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column Rows(Range("A:A").Find("x").Row + 1 & ":" & LastRow).EntireRow.Delete Range(Cells(1, Rows(1).Find("y").Column + 1), Cells(1, lColumn)).EntireColumn.Delete Application.ScreenUpdating = True End Sub
You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
Practice makes perfect. I'm very far from perfect so I'm still practising.
Thanks! This is very close, but it only deletes one column to the right of "y" and I need all columns. I will try to adjust the code.
Any idea how to make this for an Array of Sheets in a workbook?
The problem of not deleting all the columns may be due to the fact that you may not have column headers in all the columns to the right of the "y". This macro should take care of that:Do you want to run the macro on all sheets or just some? If you want to run it only on some sheets, then I would need to know the names of those sheets and/or the names of the sheets you want to exclude.![]()
Sub DeleteRowsColumns() Application.ScreenUpdating = False Dim LastRow As Long LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row Dim lColumn As Long lColumn = ActiveSheet.UsedRange.Columns.Count Rows(Range("A:A").Find("x").Row + 1 & ":" & LastRow).EntireRow.Delete Range(Cells(1, Rows(1).Find("y").Column + 1), Cells(1, lColumn)).EntireColumn.Delete Application.ScreenUpdating = True End Sub
Excellent, thanks Mumps! Works great for the sheet. The 3 sheets I would need it for are "EE", "KN", and "SEA" (See revised attachment; "Control" should remain the same).
Give this a try:![]()
Sub DeleteRowsColumns() Application.ScreenUpdating = False Dim ws As Worksheet Dim LastRow As Long Dim lColumn As Long For Each ws In Sheets If ws.Name <> "Control" Then LastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row lColumn = ws.UsedRange.Columns.Count ws.Rows(ws.Range("A:A").Find("x").Row + 1 & ":" & LastRow).EntireRow.Delete ws.Range(ws.Cells(1, ws.Rows(1).Find("y").Column + 1), ws.Cells(1, lColumn)).EntireColumn.Delete End If Next ws Application.ScreenUpdating = True End Sub
Perfect, you rock! Thanks a lot
You are very welcome.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks