试图获得使用工作表功能的范围设置COUNTIF
。这是我得到的:
Function count_if(work_sheet As String, criteria As String, column_num As Integer)
Dim rows As Integer
rows = Get_Rows_Generic(work_sheet, 1) ' get the number of rows in another sheet
Dim full_range As Range
With work_sheet
Set full_range = .Range(.Cells(0, rows), .Cells(0, column_num))
End With
count_result = WorksheetFunction.CountIf(full_range, criteria)
count_if = range_size
End Function
Sub test_stuff()
Dim n As Integer
n = count_if("usersFullOutput.csv", "TRUE", 9)
MsgBox n
End Sub
当我运行代码时,excel会要求我选择另一个宏。我猜这是我设置范围的方式,但我不知道。
第一点
如果“ usersFullOutput.csv”实际上是您工作表的名称(而不是文件名),那么使用此名称您将无法执行以下操作:
With work_sheet
Set full_range = .Range(...)
End With
范围是工作表对象的属性,而不是工作表名称字符串。尝试这样做:
With Worksheets(work_sheet)
Set full_range = .Range(...)
End With
点#2
Set full_range = .Range(.Cells(0, rows), .Cells(0, column_num))
的第一个参数Cells()
是行号。行号不能为0
。Excel中的第一行始终为1
。A1将由引用Cells(1, 1)
。也许您需要类似的东西
Set full_range = .Range(.Cells(1, 1), .Cells(rows, column_num))
第三点
range_size
未定义(该行count_if = range_size
)。
我觉得你需要
count_if = count_result
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句