• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User


  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

help to make a maro to delete first 4 row on multiple file


New Member
ok, i would like a vba code to be able to open multiple file but on each file who is open the first 4 row must be erase.


Active Member
Hi Maxwolf,

the below code should open all workbooks in a folder you specify, 1 by 1 and delete the contents of the first 4 rows before saving and closing that workbook.
If instead you want to delete the rows entirely, replace 'clearcontents' with 'delete'.

Please be very sure that you know what this will do and you want to do it before you run code like this, as VBA macros cannot be reversed with such as 'undo'.

Sub del4rows()
Dim directory As String
Dim file As String
Dim wb As Workbook
directory = "" ' place the path here, such as "C:\Users\Maxwolf\ExcelFiles"
file = Dir(directory & "\*.xlsx") ' may need to change to .xlsm or .xls as needed
Do While file <> ""
    Set wb = Workbooks.Open(directory & "\" & file)
    wb.Sheets(1).Rows("1:4").ClearContents ' this assumes you have 1 sheet per workbook, if not, may want to add a loop here
    file = Dir()
End Sub
I hope this helps, I used this post as input for the file looping part:

If this was useful, please click 'Like' on the bottom right!