At the First I tried to run my codes in VBA but It ended up error like "Procedure too large". So I tried to divide it into some subs and when i called another sub inside my main sub, It doesn't work. Before I devided into sum subs, my codes run so well.
I tried to call Private sub Calca1() inside Private Sub Commandbutton2_Click()
Here's my Code
Private Sub Calca1()
If flag60 = 1 Then
Sheets("KPIAgent").Cells(trow2 + 1, 1).Value = "Agnes"
CS_Yes = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("R4:R65536"), "Yes", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 30
CS_No = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("R4:R65536"), "No", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 0
Sheets("KPIAgent").Cells(trow2 + 1, 3).Value = (CS_Yes + CS_No) / var60
HT_Yes = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("T4:T65536"), "Yes", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 20
HT_No = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("T4:T65536"), "No", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 0
Sheets("KPIAgent").Cells(trow2 + 1, 4).Value = (HT_Yes + HT_No) / var60
H_Yes = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("V4:V65536"), "Yes", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 40
H_No = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("V4:V65536"), "No", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 0
Sheets("KPIAgent").Cells(trow2 + 1, 5).Value = (H_Yes + H_No) / var60
RP_Yes = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("X4:X65536"), "Yes", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 10
RP_No = (Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("X4:X65536"), "No", Sheets("RawData").Range("K4:K65536"), "Agnes")) * 0
Sheets("KPIAgent").Cells(trow2 + 1, 6).Value = (RP_Yes + RP_No) / varreport60
trow2 = trow2 + 1
End If
End Sub
Private Sub CommandButton2_Click()
Sheets.Add.Name = "KPIAgent"
Sheets("KPIAgent").Activate
Sheets("KPIAgent").Cells(1, 1).Value = "Agent Name"
Sheets("KPIAgent").Cells(1, 2).Value = "AVG Score"
Sheets("KPIAgent").Cells(1, 3).Value = "AVG Common Sense Score"
Sheets("KPIAgent").Cells(1, 4).Value = "AVG Human Touch Score"
Sheets("KPIAgent").Cells(1, 5).Value = "AVG Helpful Score"
Sheets("KPIAgent").Cells(1, 6).Value = "AVG Reporting Score"
Sheets("KPIAgent").Cells(1, 7).Value = "Satisfaction - STP"
Sheets("KPIAgent").Cells(1, 8).Value = "Satisfaction - TP"
Sheets("KPIAgent").Cells(1, 9).Value = "Satisfaction - P"
Sheets("KPIAgent").Cells(1, 10).Value = "Satisfaction - SP"
Sheets("KPIAgent").Columns("A:J").Select
Selection.EntireColumn.AutoFit
Sheets("KPIAgent").Range("A1:J1").Font.Bold = True
Dim i As Integer
Dim flag60 As Integer
Dim trow As Integer
Dim trow2 As Integer
Dim var60 As Integer
Dim varreport60 As Integer
var60 = Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("K4:K65536"), "Agnes")
varreport60 = Application.WorksheetFunction.CountIfs(Sheets("RawData").Range("K4:K65536"), "Agnes", Sheets("RawData").Range("Q4:Q65536"), "Recording")
trow = Sheets("RawData").UsedRange.Rows.Count
trow2 = Sheets("KPIAgent").UsedRange.Rows.Count
For i = 4 To trow
If Sheets("RawData").Cells(i, 11).Value = "Agnes" Then
flag60 = 1
End If
Next i
Dim CS_Yes As Integer
Dim CS_No As Integer
Dim CS As Integer
Dim HT_Yes As Integer
Dim HT_No As Integer
Dim HT As Integer
Dim H_Yes As Integer
Dim H_No As Integer
Dim H As Integer
Dim RP_Yes As Integer
Dim RP_No As Integer
Dim RP As Integer
Call Calca1
End Sub