I am trying to do the following. I am having two sheets.
From sheet1, I count number of 0 according to the condition and copy it in the table in sheet2.
I am doing the same with different conditions. When I am executing the code, I am getting an runtime error, Overflow. Can someone help me what is the reason.
Sub result()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim cnt As Integer
Dim cntU As Integer
Dim Sht As Worksheet
Dim totalrows As Long
Set Sht = Sheets("CTT")
Sheets("Sheet1").Select
totalrows = Range("A5").End(xlDown).Row
n = Worksheets("Sheet1").Range("A5:A" & totalrows).Cells.SpecialCells(xlCellTypeConstants).Count
For i = 2 To WorksheetFunction.Count(Sht.Columns(1))
cntT = 0
cntU = 0
Cnts = 0
cntV = 0
cntZ = 0
cntW = 0
cntA = 0
Cntb = 0
cntC = 0
cntD = 0
cntE = 0
cntF = 0
If Sht.Range("A" & i) = Val(Format(Now, "WW")) Then Exit For
Next i
For j = 5 To Sheets("Sheet1").Cells(Rows.Count, 17).End(xlUp).Row
If Sht.Range("A" & i) = Range("W" & j) And Range("Q" & j) = "D" Then cntT = cntT + 1
If Sht.Range("A" & i) = Range("W" & j) And Range("Q" & j) = "K" Then cntU = cntU + 1
If Sht.Range("A" & i) = Range("W" & j) And Range("Q" & j) = "A" Then Cnts = Cnts + 1
If Sht.Range("A" & i) = Range("W" & j) And Range("Q" & j) = "M" Then cntV = cntV + 1
If Sht.Range("A" & i) = Range("W" & j) And Range("Q" & j) = "C" Then cntW = cntW + 1
If Sht.Range("A" & i) = Range("W" & j) And Range("Q" & j) = "E" Then cntZ = cntZ + 1
If cntU <> 0 Then Sht.Range("K" & i) = cntU
If Cnts <> 0 Then Sht.Range("B" & i) = Cnts
If cntT <> 0 Then Sht.Range("E" & i) = cntT
If n <> 0 Then Sht.Range("T" & i) = n
If cntV <> 0 Then Sht.Range("N" & i) = cntV
If cntZ <> 0 Then Sht.Range("H" & i) = cntZ
If cntZ <> 0 Then Sht.Range("Q" & i) = cntW
Next j
For k = 5 To Sheets("CTT_Report").Cells(Rows.Count, 17).End(xlUp).Row
If Sht.Range("A" & i) = Range("W" & k) And Range("Q" & k) = "A" And Range("U" & k) = "0" Then cntA = cntA + 1
If Sht.Range("A" & i) = Range("W" & k) And Range("Q" & k) = "D" And Range("U" & k) = "0" Then Cntb = Cntb + 1
If Sht.Range("A" & i) = Range("W" & k) And Range("Q" & k) = "E" And Range("U" & k) = "0" Then cntC = cntC + 1
If Sht.Range("A" & i) = Range("W" & k) And Range("Q" & k) = "K" And Range("U" & k) = "0" Then cntD = cntD + 1
If Sht.Range("A" & i) = Range("W" & k) And Range("Q" & k) = "M" And Range("U" & k) = "0" Then cntE = cntE + 1
If Sht.Range("A" & i) = Range("W" & k) And Range("Q" & k) = "C" And Range("U" & k) = "0" Then cntF = cntF + 1
If cntA <> 0 Then Sht.Range("C" & i) = cntA
If Cntb <> 0 Then Sht.Range("F" & i) = Cntb
If cntC <> 0 Then Sht.Range("I" & i) = cntC
If cntD <> 0 Then Sht.Range("L" & i) = cntD
If cntE <> 0 Then Sht.Range("O" & i) = cntE
If cntF <> 0 Then Sht.Range("R" & i) = cntF
Next k
If cntA + Cnts + Cntb + cntC + cntD + cntE + cntF + cntT + cntU + cntV + cntZ <> 0 Then
Sht.Range("D" & i) = cntA / Cnts
Sht.Range("G" & i) = Cntb / cntT
Sht.Range("J" & i) = cntC / cntZ
Sht.Range("M" & i) = cntD / cntU
Sht.Range("P" & i) = cntE / cntV
Sht.Range("S" & i) = cntF / cntW
End If
End Sub