Erasing data (not rows) in specific rows in all files in a folder

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
705
Office Version
  1. 365
Platform
  1. Windows
Yep - hundreds of files named "BlahBlahBlah 2021.xlsx"
I copied all of last year's files from a folder named 2020 into a new folder named 2021. I then renamed all the files to end with 2021 but....

Each file has 31 tabs and each of those tabs has data in rows 3 through 50 that need to be deleted so a macro (I wrote with the help of people here) can update the files with new data as it becomes available. I just need the files to be exactly as they are now but with no data in rows 3-50. I can't delete those rows because that would move other cells around - just need to delete the data and leave everything else as is.

If it matters, each of the files' 31 tabs are named for each day of the month (even February, April etc - don't ask). So the multiple files for January have tabs named 01-01, 01-02, 01-03, etc. And the multiple February files have tabs named 02-01, 02-02, 02-03, ...., 02-31.

How can I do a mass change to delete data (not rows) in rows 3-50 and change nothing else?

And for everybody reading this - happy new year and thanks to the many people who have been so helpful to me on this site.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this macro. Change the folder path (in red) to suit your needs.
Rich (BB code):
Sub deleteRows()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Dim directory As String
    directory = "C:\2021\"
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set folder = FSO.GetFolder(directory)
    For Each file In folder.Files
        Workbooks.Open directory & Application.PathSeparator & file.Name
        For Each ws In Sheets
           ws.Rows("3:50").ClearContents
        Next ws
        ActiveWorkbook.Close True
    Next file
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Simple and efficient. Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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