【发布时间】:2018-02-15 01:48:02
【问题描述】:
vba 中的 countif 函数有问题(最后两行代码)。它必须计算一定范围内的某些值,但是它绝对将每个值都计为 mp3 而没有任何值计为 mp4。
最奇怪的是,当我将程序复制到一个新的单独模块中时,没有传递变量,一切正常,返回正确的值。这里有什么问题?谢谢
Private Sub FindValue(ByVal fileno As String, ByVal deadline As String)
Dim i As Integer
Dim xWs As Worksheet
Dim rng As Range
Dim olApp As Object
Dim olMail As Object
Dim var As Integer
Dim user As String
Dim uplDate As String
Const olMailItem = 0
Dim lastrow As Long
Dim mp3 As Long
Dim mp4 As Long
Sheets("Add_User_ID").Select
var = Sheets("Add_User_ID").Range(("A2"), Sheets("Add_User_ID").Range("A2").End(xlDown)).Rows.Count
If fileno = "" Then
fileno = InputBox("File number")
End If
If deadline = "" Then
deadline = InputBox("Deadline, any format(e.g. 27th of August EOD)")
End If
uplDate = Format(Date, "YYYYMMDD")
For i = 2 To var + 1
user = Sheets("Add_User_ID").Cells(i, "A").Value
Sheets("allocation").Select
With ActiveSheet
.AutoFilterMode = False
.Range("A:I").AutoFilter
.Range("A:A").AutoFilter field:=1, Criteria1:=user
End With
Sheets("allocation").Range("A1").Select
Set rng = ActiveCell.CurrentRegion
Application.Workbooks.Add
Set xWs = Application.ActiveSheet
rng.Copy Destination:=xWs.Range("A1")
lastrow = xWs.Cells(Rows.Count, 2).End(xlUp).Row - 1
mp3 = WorksheetFunction.CountIf(Range(Cells(2, 4), Cells((lastrow + 1), 4)), 3)
mp4 = WorksheetFunction.CountIf(Range(Cells(2, 4), Cells((lastrow + 1), 4)), 4)
【问题讨论】: