VBA Code to exclude sheets with no data

angelmaine4ever

New Member
Joined
Nov 1, 2017
Messages
10
Hi I have this formula below (thanks Rick Rothstein!) that combines all worksheet data in to one worksheet.

However, I need to exclude those worksheets/tab with no data at all (only with header).

PLEASE HELP ME! THANK YOU!!!

Sub Button2_Click()
Dim NextRow As Long, Sht As Worksheet
For Each Sht In Worksheets
If Sht.Name <> "Master" And Sht.Name <> "READ ME" And Sht.Name <> "PRIDE Ratings' Distribution" And Sht.Name <> "Computation" Then
NextRow = Sheets("Master").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row + 1
Sheets("Master").Cells(NextRow, "A").Value = Sht.Name
Sheets("Master").Cells(NextRow, "B").Resize(Sht.UsedRange.Rows.Count, 9) = Sht.UsedRange.Offset(1).Value
End If
Next
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I need to exclude those worksheets/tab with no data at all (only with header).

Hi, you should probably have posted this in your original thread, but maybe this amendment will work for you.

Rich (BB code):
Sub Button2_Click()
Dim NextRow As Long, Sht As Worksheet
For Each Sht In Worksheets
  If Sht.Name <> "Master" And Sht.Name <> "READ ME" And Sht.Name <> "PRIDE Ratings' Distribution" And Sht.Name <> "Computation" Then
   NextRow = Sheets("Master").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row + 1
     If Sht.UsedRange.Rows.Count > 1 Then
       Sheets("Master").Cells(NextRow, "A").Value = Sht.Name
       Sheets("Master").Cells(NextRow, "B").Resize(Sht.UsedRange.Rows.Count, 9) = Sht.UsedRange.Offset(1).Value
     End If
  End If
Next
End Sub
 
Upvote 0
Hi, you should probably have posted this in your original thread, but maybe this amendment will work for you.

Rich (BB code):
Sub Button2_Click()
Dim NextRow As Long, Sht As Worksheet
For Each Sht In Worksheets
  If Sht.Name <> "Master" And Sht.Name <> "READ ME" And Sht.Name <> "PRIDE Ratings' Distribution" And Sht.Name <> "Computation" Then
   NextRow = Sheets("Master").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row + 1
     If Sht.UsedRange.Rows.Count > 1 Then
       Sheets("Master").Cells(NextRow, "A").Value = Sht.Name
       Sheets("Master").Cells(NextRow, "B").Resize(Sht.UsedRange.Rows.Count, 9) = Sht.UsedRange.Offset(1).Value
     End If
  End If
Next
End Sub

Sir, thank you!!! It worked!!!
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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