Dear ,
Thanks for your time to have responded .In this case macro recorder can't be a solution .Since the different tabs(worksheets) of the workbook will have different used ranges for columns and rows in each of the worksheets(tabs) ,so This approach wont work ,
Let me explain -say ,i do a macro recording on first tab(worksheet) which has say 5 rows and 7 columns (used range ) ,Thm macro recorder will calculate used range based on tab 1 then i can't expect it to work on my other worksheets (tabs ) which has x used rows and y used columns(else even used range will get deleted ) .The approach would work if all the tabs have same X no of rows and y no of columns .
In my actual case i have 325 sheets with different used rows i.e ,x1,x2,x3,x4,etc no of rows in each of the sheets and y1,y2,y3,y4,y5 etc no of used columns in each of the sheets .
I think that you shall now agree that macro recording in my case wont solve it ,since used ranges of rows and columns differ in each of the tabs (worksheets )of my workbook .
On the bright side ,I tried my hands at a code which i got after a bit of research (i found many codes after reserach but i liked only this one since the coding is simple to undrstand and logical ,but it was for deleting empty rows and not columns( which i havent managed ) ,i type the code below - i hope someone can modify it to suit my needs,
Sub DeleteBlankRowsandcolumns()
Dim WS As Worksheet, R As Long, X As Long, Rngr As Range, Rngc As Range
On Error GoTo End
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each WS In Worksheets
Set Rngr = WS.UsedRange.Rows
Set Rngc = WS.UsedRange.Columns
For R = Rngr.Rows.Count To 1 Step -1
C = Rngc.Columns.Count To 1 Step 1
If Application.WorksheetFunction.CountA(Rngr.Rows(R).EntireRow) = 0 Then
Rngr.Rows(R).EntireRow.Delete
If Application.WorksheetFunction.CountA(Rngc.Columns(C).EntireColumn) = 0 Then
Rngc.Column(C).EntireColumn.Delete
End If
End If
Next R
Next WS
End:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
I know that i am using the column part in the loop in the wrong fashion ,if someone can edit the code to make it workable ,i will be really glad !
Thanks again to everyone who would be looking into this ,i really really appreciate !
Regards ,
Amlan Dutta
Bookmarks