Delete the same row in multiple worksheets in a workbook

kasinger

New Member
Joined
Dec 18, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
The code I am using runs only on the active sheet. It does not cycle through the workbook. Can anyone tell me how I can fix the problem?

Sub Project2()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Portfolio" Then
Rows(37).EntireRow.Delete
End If
Next ws

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi & welcome to Mr.Excel!

Qualify your range and you're good:
Rich (BB code):
Sub Project2()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
  If ws.Name <> "Portfolio" Then 
    ws.Rows(37).EntireRow.Delete
  End If
Next ws

End Sub
 
Upvote 0
Hi, Rich. Added ws. and the sub would not run at all after that change.
 
Upvote 0
It works for me. What do you mean with "would not run at all after that change"
Are you getting an error message and if so, what is it saying?
 
Upvote 0
Rich, When I run the original version, the one I posted, it deletes row 37 from the active worksheet, but not all sheets, which is what I am aiming for. When ws. was added, there were no error messages, but nothing was deleted from row 37 in any of the sheets. Thanks! Keith
 
Upvote 0
The code only affects the worksheets of the workbook where this code runs, with the exception of the worksheet named "Portfolio".
If another workbook is active, you will not notice any changes in that active workbook.
 
Upvote 0

Forum statistics

Threads
1,223,974
Messages
6,175,739
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top