KaibleBasha
New Member
- Joined
- Aug 8, 2014
- Messages
- 36
Hi
I am trying to ascertain worker caseloads for workers within the service for which I work by using the below;
Sub CommandButton1_Click()
Dim a, b, c, d, e, f, g, h As Integer
Dim CC, LB, KC, TH As String
Dim LstRw, Rw As Long
Sheets("Recovery Caseload").Select
LstRw = Cells(Rows.Count, "C").End(xlUp).Row
CC = "Worker1"
LB = "Worker2"
KC = "Worker3"
TH = "Worker4"
a = 2
b = 2
c = 2
d = 2
e = 0
f = 0
g = 0
h = 0
Do While a <=LstRw
If Cells(a,"C") = CC Then e = e + 1
a = a + 1
Loop
CCCheck = MsgBox(LstRw & " " & e, vbOKOnly, "Caseloads - " & _
"Primary & Secondary worked")
End Sub
When I get the message box to display the result states "0 0" meaning there are 0 rows and 0 cells meeting my criteria, however the are about 370 rows, many of which match the criteria.
I have frequently used the LstRw as long and Cells(Rows.Count,"A") to find the last row of data on a given column, however this time is doesn't want to work. Though when I do this, it does (just curious why);
With Activesheet
LstRw = .Cells(.Rows.Count,"A").End(xlUp).Row
End With
After this I need to count the number of times a worker's name appears (e.g. Worker1 appearing 130 times), by totalling each instance and giving "e" a value. Then repeating this for workers2/3/4 and letters f,g & h.
Are you able to see what I'm doing wrong here? Is it the "Dim" at the top as this is the only thing I have really done differently compared to other macros
Thanks
Kai
I am trying to ascertain worker caseloads for workers within the service for which I work by using the below;
Sub CommandButton1_Click()
Dim a, b, c, d, e, f, g, h As Integer
Dim CC, LB, KC, TH As String
Dim LstRw, Rw As Long
Sheets("Recovery Caseload").Select
LstRw = Cells(Rows.Count, "C").End(xlUp).Row
CC = "Worker1"
LB = "Worker2"
KC = "Worker3"
TH = "Worker4"
a = 2
b = 2
c = 2
d = 2
e = 0
f = 0
g = 0
h = 0
Do While a <=LstRw
If Cells(a,"C") = CC Then e = e + 1
a = a + 1
Loop
CCCheck = MsgBox(LstRw & " " & e, vbOKOnly, "Caseloads - " & _
"Primary & Secondary worked")
End Sub
When I get the message box to display the result states "0 0" meaning there are 0 rows and 0 cells meeting my criteria, however the are about 370 rows, many of which match the criteria.
I have frequently used the LstRw as long and Cells(Rows.Count,"A") to find the last row of data on a given column, however this time is doesn't want to work. Though when I do this, it does (just curious why);
With Activesheet
LstRw = .Cells(.Rows.Count,"A").End(xlUp).Row
End With
After this I need to count the number of times a worker's name appears (e.g. Worker1 appearing 130 times), by totalling each instance and giving "e" a value. Then repeating this for workers2/3/4 and letters f,g & h.
Are you able to see what I'm doing wrong here? Is it the "Dim" at the top as this is the only thing I have really done differently compared to other macros
Thanks
Kai