Macro to delete blank rows & columns from files

Alka Bajaj

New Member
Joined
Apr 5, 2011
Messages
44
Hello Expert,
There are number of report exported daily from SAP application. All these are stored in a folder.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I need to merge all this reports into one . But before I do, I have to perform following steps<o:p></o:p>
<o:p> </o:p><o:p> </o:p>
Steps Performed:<o:p></o:p>
<o:p> </o:p>
1. Open the file ( Since the files are exported, every time I receive a warning message “Excel export: The file you are trying to open, '[filename]', is in a different format than specified by the file extension…. Do you want to open the file now”). <o:p></o:p>
2. Click “Yes’<o:p></o:p>
3. Delete first 4 blank rows<o:p></o:p>
4. Delete 6<SUP>th</SUP> blank row<o:p></o:p>
5. Delete first 5 blank columns<o:p></o:p>
6. Save the file as excel<o:p></o:p>
7. Loop through all the files in a folder<o:p></o:p>
<o:p> </o:p>
Appreciate if you can guide me to automate above steps using macro. If I can automate above, for all the files in a folder.
<o:p></o:p>
<o:p>I am not able to attach the sample file. Let me know if it is required to be mailed.</o:p>
<o:p></o:p>
Awaiting your support and help.<o:p></o:p>
<o:p> </o:p>
Many thanks!<o:p></o:p>
<o:p> </o:p>
Regards,<o:p></o:p>
Alka <o:p></o:p>
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try something like this

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Open_My_Files()<br><SPAN style="color:#007F00">'Open all workbooks</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> MyFile <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">Dim</SPAN> myPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>myPath = "M:\Access Files\" <SPAN style="color:#007F00">'Change path</SPAN><br>MyFile = Dir(myPath)<br><br><SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> MyFile <> ""<br><SPAN style="color:#00007F">If</SPAN> MyFile <SPAN style="color:#00007F">Like</SPAN> "*.xls" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'Check file extension</SPAN><br>Workbooks.Open myPath & MyFile<br>Range("1:4,6:6").Delete Shift:=xlUp<br>Columns("A:E").Delete Shift:=xlToLeft<br>ActiveWorkbook.Save <SPAN style="color:#007F00">'You will need to check this out</SPAN><br>ActiveWorkbook.Close <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>MyFile = Dir<br><SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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