2016-04-15 11 views
1

理論的には、月単位でフィルタリングするというこのコンセプトは有効ですが、そうではありません。私は、各割り当てが完了したことを記録し、標準フォーマットで日付を記入するフォームを使用しています。私はこのコードがこの形式の日付を数えない理由について混乱しています。フォームの各月は、常に1桁の月間はx/xx/xxxx、2桁の月はxx/xx/xxxxとして形式化されます。私の考えでは、毎月の文字で始まり、それを数えるセルを見つけることは、私の必要性のための簡単な概念でなければなりません。問題は、このフィルタに基づいて行をカウントすると、0を返します。何が起こっているのか誰かが知っていますか?オートフィラ(VBA)を使用して条件を指定して月をフィルタリングする

ありがとうございます!

With iTable 
     .AutoFilter 
     .AutoFilter Field:=1, Criteria1:=tin 
     .AutoFilter Field:=3, Criteria1:="=1/*" 
     End With 
     TData.Cells(i, 4).Value = iTable.Resize(, 1).SpecialCells(xlCellTypeVisible).Count - 1 


     With iTable 
     .AutoFilter 
     .AutoFilter Field:=1, Criteria1:=tin 
     .AutoFilter Field:=3, Criteria1:="=2/*" 
     End With 
     TData.Cells(i, 5).Value = iTable.Resize(, 1).SpecialCells(xlCellTypeVisible).Count - 1 

答えて

0

ヶ月あたりの正確なカウントを取得するには、MONTH functionと「ヘルパー」列右に未使用の列を使用することができます。この「ヘルパー」列は、Range.AutoFilter Methodの基準として目的を果たした後で削除することができます。

あなたはまた、C列の日付のクイックConditional Formattingを書いて、列に.AutofilterにOperator:=xlFilterCellColorオプションを適用することができC.

Option Explicit 

Sub Macro2() 
    Dim m As Long, n As Long, tin As String, vMNTHs As Variant 

    vMNTHs = Array(1, 2) 
    tin = "tin" 

    With Worksheets("sheet3") 
     If .AutoFilterMode Then .AutoFilterMode = False 
     With .Cells(1, 1).CurrentRegion 
      For m = LBound(vMNTHs) To UBound(vMNTHs) 
       If .Parent.AutoFilterMode Then .Parent.AutoFilterMode = False 
       With .Resize(.Rows.Count - 1, 1).Offset(1, 2) 
        .FormatConditions.Add Type:=xlExpression, Formula1:="=MONTH(C2)=" & vMNTHs(m) 
        .FormatConditions(.FormatConditions.Count).SetFirstPriority 
        .FormatConditions(1).Interior.Color = vbRed 
        .FormatConditions(1).StopIfTrue = True 
       End With 

       .AutoFilter Field:=1, Criteria1:=tin, Operator:=xlFilterValues 
       .AutoFilter Field:=3, Criteria1:=vbRed, Operator:=xlFilterCellColor 

       n = Application.Subtotal(102, Columns(3)) 
       MsgBox "the count for " & Format(DateSerial(2016, vMNTHs(m), 1), "mmmm") & " is " & n 

       With .Resize(.Rows.Count - 1, 1).Offset(1, 2) 
        .FormatConditions(1).Delete 
       End With 
      Next m 
     End With 
     If .AutoFilterMode Then .AutoFilterMode = False 
    End With 
End Sub 
+0

が、私はこれが答えかもしれないと思う、ありがとうございます。私はすでに情報を並べ替えるための列を備えた一時的なタブを使用しています。私は月の機能についても考えていませんでした! 残念ながら、私はオフィスに戻ってきた月曜日までこれを試すことはできません。私はあなたを更新し続けるつもりです! – theMagicOne

+0

私は自宅のコンピュータで簡単なバージョンをテストすることができました。あなたは命を救う人です、ありがとう。どのような簡単な修正! – theMagicOne

関連する問題