Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 对预定义值进行计数_Excel_Vba - Fatal编程技术网

Excel 对预定义值进行计数

Excel 对预定义值进行计数,excel,vba,Excel,Vba,我希望使用countifs()来帮助缩小计数参数的范围,尽管我无法基于代码中的上述内容设置参数 我有用户输入的一年和一个月分别;我想在countifs语句中使用这个输入,尽管我没有这样的运气 为了进行合理性检查,我输入了具体的月份和年份值,并能够得到正确的答案 代码如下: Sub Investigations() 'Return to Overview sheet before running as non-subsequent columns may receive output if vi

我希望使用countifs()来帮助缩小计数参数的范围,尽管我无法基于代码中的上述内容设置参数

我有用户输入的一年和一个月分别;我想在countifs语句中使用这个输入,尽管我没有这样的运气

为了进行合理性检查,我输入了具体的月份和年份值,并能够得到正确的答案

代码如下:

Sub Investigations()

'Return to Overview sheet before running as non-subsequent columns may receive output if viewing another sheet
Sheets("Overview").Select

'Define year and month
Dim zYear As Integer
    zYear = InputBox("Year (yyyy)")
Dim zMonth As Integer
    zMonth = InputBox("Month (mm)")

'Define zYear and zMonth on the spreadsheet so it can be referenced
Sheets("Investigations").Range("L1").Value = zYear
Sheets("Investigations").Range("M1").Value = zMonth

'Count of total minor investigations
Dim LastCol1 As Long
LastCol1 = Range("A12").End(xlToRight).Column
Sheets("Overview").Cells(12, LastCol1 + 1).Formula = "=countif(Investigations!H:H,""Low"")"

'Define and count minor investigations closed on time (<31 days), in the pre-defined year and month
Dim LastRow As Integer
LastRow = Range("A2").End(xlDown).Row
Sheets("Investigations").Range("I1").Formula = "Time to Close (Days)"
Sheets("Investigations").Range("I2:I" & LastRow).Formula = "=if(F2>0,abs(F2-E2),""N/A"")"
Sheets("Investigations").Range("J1").Formula = "Month of Closure"
Sheets("Investigations").Range("J2:J" & LastRow).Formula = "=if(F2>0,month(F2),""N/A"")"
Sheets("Investigations").Range("K1").Formula = "Closed in Defined Month"
Sheets("Investigations").Range("K2:K" & LastRow).Formula = "=IF(J2=$M$1,TRUE,FALSE)"

'Count of closed minor investigation in pre-defined year and month
Sheets("Overview").Cells(13, LastCol1 + 1).Formula = "=COUNTIFS(Investigations!H:H,""Low"",Investigations!I:I,""<31"",Investigations!K:K,""True"")"


End Sub
子调查()
'在运行之前返回概览表,因为如果查看其他工作表,非后续列可能会收到输出
工作表(“概述”)。选择
'定义年份和月份
作为整数的Dim zYear
zYear=InputBox(“年(yyyy)”)
作为整数的Dim zMonth
zMonth=输入框(“月(mm)”)
'在电子表格上定义zYear和zMonth,以便可以引用
表(“调查”)。范围(“L1”)。值=zYear
表(“调查”)。范围(“M1”)。值=z个月
"轻微调查总数
暗淡的LastCol1一样长
LastCol1=范围(“A12”)。结束(xlToRight)。列
表格(“概述”).单元格(12,LastCol1+1).Formula=“=countif(调查!H:H”,“低”)

“定义并统计按时结束的次要调查(我找不到原始问题的答案,通过将zMonth和zYear放在单元格引用的工作表上找到了解决办法。

您能将具体错误和错误发生的那一行添加到问题文本中吗?添加了以下注释:没有错误消息。当代码返回时,计数返回零正在运行。健全性检查返回38项(从>8k行中删除)。我的问题是,我不知道如何在我的countif中适当地引用zMonth和zRange,因为它们实际上不存在于任何工作表中,只存在于代码中。祝贺您弄明白了这一点,很抱歉,我帮不了更多忙。干得好!