Thank you ! Got it done
the code is
Code:
Option Explicit
Public Sub TallyZerosOnActiveSheet()
Dim SourceSh As Worksheet
Dim CurrentCountRange As Range
Dim ETOHCountRange As Range
Dim ZeroCount As Long
Dim ETOHcount As Long
Dim Biocount As Long
Dim ETOHBiocount As Long
Dim NextRow As Long
Dim iRow As Long
Dim ColWithHdr
' CONFIG HERE !!
Const analysisSh As String = "Analysis"
Const SrcHdrRow As Integer = 1
NextRow = 160108
'Set Source Sheet
Set SourceSh = ActiveSheet
'Make sure Anlaysis Sheet Exist
If Not SheetExists(analysisSh) Then
Sheets.Copy after:=ActiveSheet
ActiveSheet.Name = analysisSh
End If
With SourceSh
' Cycle thru all columns that have header
For Each ColWithHdr In .Rows(SrcHdrRow & ":" & SrcHdrRow).SpecialCells(xlCellTypeConstants, 2)
' Set range to count
Set CurrentCountRange = .Cells(1, ColWithHdr.Column).EntireColumn
'Set ETOHCountRange = .Cells(1, 1).EntireColumn
' Count zeros
ZeroCount = Application.WorksheetFunction.CountIf(CurrentCountRange, 0)
ETOHcount = 0
Biocount = 0
ETOHBiocount = 0
For iRow = 1 To 160106
If Cells(iRow, ColWithHdr.Column) = 0 Then
If Not (Cells(iRow, 1) = 0) Then
ETOHcount = ETOHcount + 1
End If
If Not (Cells(iRow, 68) = 0) Then
Biocount = Biocount + 1
End If
If Not ((Cells(iRow, 68) = 0) Or (Cells(iRow, 1) = 0)) Then
ETOHBiocount = ETOHBiocount + 1
End If
End If
Next iRow
' Log Zeros
With Sheets(analysisSh)
'NextRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
NextRow = NextRow + 1
.Cells(NextRow, 1).Value = ColWithHdr.Value
.Cells(NextRow, 2).Value = ZeroCount
.Cells(NextRow, 3).Value = ETOHcount
.Cells(NextRow, 4).Value = Biocount
.Cells(NextRow, 5).Value = ETOHBiocount
End With
Next ColWithHdr
End With
End Sub
Private Function SheetExists(sname) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then SheetExists = True _
Else SheetExists = False
End Function
Bookmarks