Delete rows in multiples sheets

edsonpaula

New Member
Joined
Mar 22, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,
I need to create a macro to delete rows from A3 till the last line for specifics sheets (that I'll specify in the macro), I have created a macro for delete, but I'm having trouble creating a macro that runs this deletion for a range of sheets.
perhaps there is a better way of doing it.
here the code that I create for the deletion
VBA Code:
Private Sub DeleteRows()
   
    Range("A3:AC3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete
End Sub

Thank you very much
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How many sheets do you want this to work on & how many sheets should be left alone?
 
Upvote 0
Ok how about
VBA Code:
Private Sub DeleteRows()
   Dim ws As Worksheet
   
   For Each ws In Worksheets
      Select Case ws.Name
         Case "Sheet1", "Sheet2", "Sheet3"
         Case Else
            ws.Range("A3:AC" & ws.Range("A" & Rows.Count).End(xlUp).Row).EntireRow.Delete
      End Select
   Next ws
End Sub
Change Sheet1 etc to she names of the sheets that should be left alone.
 
Upvote 0
Solution
Ok how about
VBA Code:
Private Sub DeleteRows()
   Dim ws As Worksheet
  
   For Each ws In Worksheets
      Select Case ws.Name
         Case "Sheet1", "Sheet2", "Sheet3"
         Case Else
            ws.Range("A3:AC" & ws.Range("A" & Rows.Count).End(xlUp).Row).EntireRow.Delete
      End Select
   Next ws
End Sub
Change Sheet1 etc to she names of the sheets that should be left alone.
I can't express how grateful I'm for your help!
Thank you very much for the help, I'm doing some udemy courses to improve my skills!

regards,
Edson
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,036
Members
449,062
Latest member
mike575

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