Deleting blank worksheets

  • Thread starter Thread starter Lvenom
  • Start date Start date
L

Lvenom

My data is imported from a seperate program and the other progra
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
blank worksheets. Is there any way to right a macro to delete only th
blank worksheets? Thank you for any help provided
 
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 help
 
Thank you for the quick response. I tried the code supplied but I get a
error at

wks.Delete
Doesn't recognize this I guess. I am working with Excel 97 so maybe
just have a tired program...
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top