WorksheetFunction not working correctly

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

I using the following code in one of my worksheets. It is show a very
perculiar result. When I run it normally, form a button on the worksheet, I
get "0" for all my result. Which means the right part of the equations are
not working correctly. But when I run it in debug mode, that is press "F8" to
step-through the code, everything works fine. I get the correct values.
Any ideas why it is doing these?
Thanks.

If Worksheets(wsheetName).Range("E2") <> "" Then
Worksheets(wsheetName).Range("A19").Value =
Application.WorksheetFunction.CountIf(Range("E2:E16"), "Completed")
Worksheets(wsheetName).Range("D19") =
Application.WorksheetFunction.CountIf(Range("E2:E16"), "In-Progress")
End If
If Worksheets(wsheetName).Range("K2") <> "" Then
Worksheets(wsheetName).Range("G19").Value =
Application.WorksheetFunction.CountIf(Range("K2:K16"), "Completed")
Worksheets(wsheetName).Range("J19") =
Application.WorksheetFunction.CountIf(Range("K2:K16"), "In-Progress")
End If
If Worksheets(wsheetName).Range("E24") <> "" Then
Worksheets(wsheetName).Range("A41").Value =
Application.WorksheetFunction.CountIf(Range("E24:E38"), "Completed")
Worksheets(wsheetName).Range("D41") =
Application.WorksheetFunction.CountIf(Range("E24:E38"), "In-Progress")
End If
If Worksheets(wsheetName).Range("K24") <> "" Then
Worksheets(wsheetName).Range("G41").Value =
Application.WorksheetFunction.CountIf(Range("K24:K38"), "Completed")
Worksheets(wsheetName).Range("J41") =
Application.WorksheetFunction.CountIf(Range("K24:K38"), "In-Progress")
End If
 
I'd try qualifying the ranges in the countif() expression.

Maybe...
Worksheets(wsheetName).Range("A19").Value = Application.WorksheetFunction _
.CountIf(Worksheets(wsheetName).Range("E2:E16"), "Completed")

Or whatever worksheet owns that range("E2:E16")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top