我正在“尝试”制作一个消息框,在一列中显示出席和缺席的人数,这样用户就可以单击ok并复制数据,或者按cancel并结束代码。
问题是,在消息框中显示缺席和出席的人数之前,我似乎无法让CountIf部件在其中统计缺席和出席的人数。
我是编程新手,所以它可能真的很混乱,但如果有任何帮助,我将不胜感激:)
Sub SubmitAttendance()
Dim Response As String
Dim Question As String
Dim PresentNumber As String
Dim AbsentNumber As String
Function As Integer
PresentNumber = Countif(Range("E:E"), Present)
AbsentNumber = Countif(Range("E:E"), Absent)
End Function
Question = "PresentNumber Present and AbsentNumber Absent"
Response = MsgBox(Question, vbOKCancel, "Register Totals")
If Response = vbOK Then
Range("E:E").Select
Selection.Copy
Range("F:ZZ").Find("").Select
Selection.PasteSpecial
Else
Exit Function
End If
End Sub发布于 2013-04-10 22:14:11
WorkSheetFunctions模块中提供了Excel函数,例如:
WorksheetFunctions.CountIf(Arg1 As Range, Arg2)此外,将第二个参数作为字符串传递,而不是变量(VB的忙碌特性会为您声明一个该名称的未初始化变量,这可能不是您想要的。
所以你的CountIf代码行应该是这样的:
WorksheetFunction.CountIf( Range("E:E") , "Present")https://stackoverflow.com/questions/15928250
复制相似问题