2016-10-06 9 views
0

変数でCountIfsを使用する場所を見つけることができません。なぜ、「Object Requried」エラーを出すのですか?コメントに基づいてVBAを使用してCountIfsを変数で使用する方法

Dim recTable As ListObject 
Dim EOM As Date 
Dim Pending As Double 

For x = 1 To RecordCount 
    If Not IsNull(recTable.DataBodyRange(x, 7).Value) Then 
        Pending = Pending + WorksheetFunction.CountIfs(recTable.DataBodyRange(x, 2).Value, "<=" & EOM, recTable.DataBodyRange(x, 7).Value, ">" & EOM) 
       ElseIf IsNull(recTable.DataBodyRange(x, 7).Value) And Not IsNull(recTable.DataBodyRange(x, 6).Value) Then 
        Pending = Pending + Application.WorksheetFunction.CountIfs(recTable.DataBodyRange(x, 2).Value, "" <= "" & EOM, recTable.DataBodyRange(x, 6).Value, "" > "" & EOM) 
       Else 
        Pending = Pending + 1 
      End If 
     Debug.Print Pending 
Next x 
+0

あなたは2つの二重引用符は、単一の二重引用符 '「である必要がありますする必要はありません」<=「」' "'でなければなりません<= " –

+0

しかし、私はまだ" Object Required "というエラーが出ます。 – Hawsidog

+0

'' ">" "'を '' '>' 'に変更しましたか? – YowE3K

答えて

1

、私は次のことをお勧めします。

Dim recTable As ListObject 
Dim EOM As Date 
Dim Pending As Double ' Maybe Long or Integer? 

'recTable is not set in the posted code, but I assume it is in the actual code 
'EOM is not set in the posted code, but I assume it is in the actual code 
'RecordCount is not declared or set in the posted code, but I assume it is in the actual code 
'x is not declared in the posted code, but I assume it is in the actual code 

With recTable 
    For x = 1 To RecordCount 
     If Not IsNull(.DataBodyRange(x, 7).Value) Then 
      If .DataBodyRange(x, 2).Value <= EOM And _ 
       .DataBodyRange(x, 7).Value > EOM Then 
       Pending = Pending + 1 
      End If 
     ElseIf Not IsNull(.DataBodyRange(x, 6).Value) Then 
      If .DataBodyRange(x, 2).Value <= EOM And _ 
       .DataBodyRange(x, 6).Value > EOM The 
       Pending = Pending + 1 
      End If 
     Else 
      Pending = Pending + 1 
     End If 
     Debug.Print Pending 
    Next x 
End With 
関連する問題