ndendrinos
Well-known Member
- Joined
- Jan 17, 2003
- Messages
- 1,694
Hello to all
Need to add to this routine the following “IF”
And that is if a sheet is empty do not list in the newly formed sheet.
Right now if all number between MaxNum and MinNum for each sheet in the WB are there
what I get on the newly created sheet is the names of the sheets that are completely empty.
Here is the macro:
Public Sub CheckMissingFiles()
Dim Sh As Worksheet
Dim MinNum, MaxNum, Num As Integer
' CREAT A NEW SHEET FOR LIST
Sheets.Add before:=ActiveSheet
'INSPECT EACH SHEET IN BOOK
For Each Sh In Worksheets
If Not Sh.Name = ActiveSheet.Name And Not Sh.Name = "DataSheet" Then
'ESTABLISH MIN AND MAX NUMBERS FOR SHEET
MinNum = WorksheetFunction.Min(Sh.Columns("C:C"))
MaxNum = WorksheetFunction.Max(Sh.Columns("C:C"))
'LOOP THRU ALL VALUES BETWEEN MIN AND MAX , IN CURR SHEET
For Num = MinNum To MaxNum
' IF NOT FOUND RECORD ON NEW SHEET THEN LIST ON SHEET
If WorksheetFunction.CountIf(Sh.Columns("C:C"), Num) = 0 Then
NxRow = Cells(65536, 1).End(xlUp).Row + 1
Cells(NxRow, 1).Value = Sh.Name
Cells(NxRow, 2).Value = Num
End If
Next Num
End If
Next Sh 'LOOP TO NEXT SHEET
End Sub
Thank you
Need to add to this routine the following “IF”
And that is if a sheet is empty do not list in the newly formed sheet.
Right now if all number between MaxNum and MinNum for each sheet in the WB are there
what I get on the newly created sheet is the names of the sheets that are completely empty.
Here is the macro:
Public Sub CheckMissingFiles()
Dim Sh As Worksheet
Dim MinNum, MaxNum, Num As Integer
' CREAT A NEW SHEET FOR LIST
Sheets.Add before:=ActiveSheet
'INSPECT EACH SHEET IN BOOK
For Each Sh In Worksheets
If Not Sh.Name = ActiveSheet.Name And Not Sh.Name = "DataSheet" Then
'ESTABLISH MIN AND MAX NUMBERS FOR SHEET
MinNum = WorksheetFunction.Min(Sh.Columns("C:C"))
MaxNum = WorksheetFunction.Max(Sh.Columns("C:C"))
'LOOP THRU ALL VALUES BETWEEN MIN AND MAX , IN CURR SHEET
For Num = MinNum To MaxNum
' IF NOT FOUND RECORD ON NEW SHEET THEN LIST ON SHEET
If WorksheetFunction.CountIf(Sh.Columns("C:C"), Num) = 0 Then
NxRow = Cells(65536, 1).End(xlUp).Row + 1
Cells(NxRow, 1).Value = Sh.Name
Cells(NxRow, 2).Value = Num
End If
Next Num
End If
Next Sh 'LOOP TO NEXT SHEET
End Sub
Thank you