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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,671
Office Version
  1. 365
Platform
  1. Windows
How many sheets do you want this to work on & how many sheets should be left alone?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,671
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

edsonpaula

New Member
Joined
Mar 22, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,671
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,791
Messages
5,638,340
Members
417,021
Latest member
moon miner

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
Top