Delete Worksheets that only contain 2 rows of data

J

joecrabtree

To all,

I have a series of worksheets that I am performing calculations on.
However some of them only have two rows of data, and I don't want these
workskeets. How can I write a macro that will search through my
worksheets, and delete all of the ones with two rows of data or less?

I don't know if this is possible, but any help would be appreciated.

Thanks

Regards

Joseph Crabtree
 
R

Ron de Bruin

Hi joecrabtree

Basic example is this, there is no error check if all sheets have 2 rows or
less rows with data.
You can't delete all sheets in a workbook

Also the UsedRange can be bigger then you think
But see if this is working for you

Sub test()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.UsedRange.Rows.Count < 3 Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
End If
Next sh
End Sub
 

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

Top