Deleting blank worksheets
My data is imported from a seperate program and the other program automatically opens a new work book when the import starts. My problem, the data only resides on the first worksheet and then there are 2 to 3 blank worksheets. Is there any way to right a macro to delete only the blank worksheets? Thank you for any help provided. -- Lvenom ------------------------------------------------------------------------ Lvenom's Profile: http://www.excelforum.com/member.php...o&userid=35358 View this thread: http://www.excelforum.com/showthread...hreadid=552065 |
Deleting blank worksheets
try Sub a() Dim rng As Range Dim wks As Worksheet Application.DisplayAlerts = False For Each wks In ThisWorkbook.Worksheets() If wks.UsedRange.Cells.Count <= 1 Then wks.Delete End If Next Application.DisplayAlerts = True End Sub note that the count test is against a value of 1 Hope this helps -- tony h ------------------------------------------------------------------------ tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074 View this thread: http://www.excelforum.com/showthread...hreadid=552065 |
Deleting blank worksheets
Thank you for the quick response. I tried the code supplied but I get an error at wks.Delete Doesn't recognize this I guess. I am working with Excel 97 so maybe I just have a tired program.... -- Lvenom ------------------------------------------------------------------------ Lvenom's Profile: http://www.excelforum.com/member.php...o&userid=35358 View this thread: http://www.excelforum.com/showthread...hreadid=552065 |
Deleting blank worksheets
The code does assume you have data on at least one worksheet. If none have data on them then it will error on trying to delete the last sheet. So import your data then run the macro -- tony h ------------------------------------------------------------------------ tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074 View this thread: http://www.excelforum.com/showthread...hreadid=552065 |
All times are GMT +1. The time now is 02:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com