ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   WorksheetFunction not working correctly (https://www.excelbanter.com/excel-discussion-misc-queries/195953-worksheetfunction-not-working-correctly.html)

Ayo

WorksheetFunction not working correctly
 
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:E1 6"), "Completed")
Worksheets(wsheetName).Range("D19") =
Application.WorksheetFunction.CountIf(Range("E2:E1 6"), "In-Progress")
End If
If Worksheets(wsheetName).Range("K2") < "" Then
Worksheets(wsheetName).Range("G19").Value =
Application.WorksheetFunction.CountIf(Range("K2:K1 6"), "Completed")
Worksheets(wsheetName).Range("J19") =
Application.WorksheetFunction.CountIf(Range("K2:K1 6"), "In-Progress")
End If
If Worksheets(wsheetName).Range("E24") < "" Then
Worksheets(wsheetName).Range("A41").Value =
Application.WorksheetFunction.CountIf(Range("E24:E 38"), "Completed")
Worksheets(wsheetName).Range("D41") =
Application.WorksheetFunction.CountIf(Range("E24:E 38"), "In-Progress")
End If
If Worksheets(wsheetName).Range("K24") < "" Then
Worksheets(wsheetName).Range("G41").Value =
Application.WorksheetFunction.CountIf(Range("K24:K 38"), "Completed")
Worksheets(wsheetName).Range("J41") =
Application.WorksheetFunction.CountIf(Range("K24:K 38"), "In-Progress")
End If

Dave Peterson

WorksheetFunction not working correctly
 
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")

Ayo wrote:

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:E1 6"), "Completed")
Worksheets(wsheetName).Range("D19") =
Application.WorksheetFunction.CountIf(Range("E2:E1 6"), "In-Progress")
End If
If Worksheets(wsheetName).Range("K2") < "" Then
Worksheets(wsheetName).Range("G19").Value =
Application.WorksheetFunction.CountIf(Range("K2:K1 6"), "Completed")
Worksheets(wsheetName).Range("J19") =
Application.WorksheetFunction.CountIf(Range("K2:K1 6"), "In-Progress")
End If
If Worksheets(wsheetName).Range("E24") < "" Then
Worksheets(wsheetName).Range("A41").Value =
Application.WorksheetFunction.CountIf(Range("E24:E 38"), "Completed")
Worksheets(wsheetName).Range("D41") =
Application.WorksheetFunction.CountIf(Range("E24:E 38"), "In-Progress")
End If
If Worksheets(wsheetName).Range("K24") < "" Then
Worksheets(wsheetName).Range("G41").Value =
Application.WorksheetFunction.CountIf(Range("K24:K 38"), "Completed")
Worksheets(wsheetName).Range("J41") =
Application.WorksheetFunction.CountIf(Range("K24:K 38"), "In-Progress")
End If


--

Dave Peterson


All times are GMT +1. The time now is 10:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com