我目前正在編寫一個宏,它將讀取日期列,檢查每個項目的月份,在變量中記錄數字,並將最終數字放入單元格中。該計劃正在查看2999項的一列。該列未完全填滿。該數字被選中是因爲項目的數量可能會很高。否則如果語句默認爲最後一個條件vba
每個循環檢查每個單元格的月份,並將該月份的變量增加1.但最後,十二月變量大約爲2500.只有大約500個填充行。月的總和達到2999(被搜索的行數)。我不確定它爲什麼這樣做。我嘗試添加「其他」條件。它甚至沒有達到那麼遠。 A15永遠不會充滿「蝙蝠俠」。我必須錯過簡單的東西。幫幫我?
Dim rng3 As Range
Dim JanCount As Integer
Dim FebCount As Integer
Dim MarCount As Integer
Dim AprCount As Integer
Dim MayCount As Integer
Dim JunCount As Integer
Dim JulCount As Integer
Dim AugCount As Integer
Dim SepCount As Integer
Dim OctCount As Integer
Dim NovCount As Integer
Dim DecCount As Integer
Dim dateValue As Date
Dim monthInt As Integer
Set rng3 = Sheets("Sheet2").Range("K2:K3000")
For Each cell In rng3
dateValue = cell.Value
monthInt = month(dateValue)
If monthInt = 1 Then
JanCount = JanCount + 1
ElseIf monthInt = 2 Then
FebCount = FebCount + 1
ElseIf monthInt = 3 Then
MarCount = MarCount + 1
ElseIf monthInt = 4 Then
AprCount = AprCount + 1
ElseIf monthInt = 5 Then
MayCount = MayCount + 1
ElseIf monthInt = 6 Then
JunCount = JunCount + 1
ElseIf monthInt = 7 Then
JulCount = JulCount + 1
ElseIf monthInt = 8 Then
AugCount = AugCount + 1
ElseIf monthInt = 9 Then
SepCount = SepCount + 1
ElseIf monthInt = 10 Then
OctCount = OctCount + 1
ElseIf monthInt = 11 Then
NovCount = NovCount + 1
ElseIf monthInt = 12 Then
DecCount = DecCount + 1
Else
Sheets("Sheet1").Range("A15") = "Batman"
End If
Next cell
Sheets("Sheet1").Range("A10") = "Bugs in Jan"
Sheets("Sheet1").Range("B10") = "Bugs in Feb"
Sheets("Sheet1").Range("C10") = "Bugs in Mar"
Sheets("Sheet1").Range("D10") = "Bugs in Apr"
Sheets("Sheet1").Range("E10") = "Bugs in May"
Sheets("Sheet1").Range("F10") = "Bugs in Jun"
Sheets("Sheet1").Range("G10") = "Bugs in Jul"
Sheets("Sheet1").Range("H10") = "Bugs in Aug"
Sheets("Sheet1").Range("J10") = "Bugs in Oct"
Sheets("Sheet1").Range("K10") = "Bugs in Nov"
Sheets("Sheet1").Range("L10") = "Bugs in Dec"
Sheets("Sheet1").Range("A11") = JanCount
Sheets("Sheet1").Range("B11") = FebCount
Sheets("Sheet1").Range("C11") = MarCount
Sheets("Sheet1").Range("D11") = AprCount
Sheets("Sheet1").Range("E11") = MayCount
Sheets("Sheet1").Range("F11") = JunCount
Sheets("Sheet1").Range("G11") = JulCount
Sheets("Sheet1").Range("H11") = AugCount
Sheets("Sheet1").Range("I11") = SepCount
Sheets("Sheet1").Range("J11") = OctCount
Sheets("Sheet1").Range("K11") = NovCount
Sheets("Sheet1").Range("L11") = DecCount
小區A15是不是蝙蝠俠!我是蝙蝠俠! – mattboy
如果你發佈你的輸入,我們可能會有更多的工作與@AndyArduesser –
你可以放置一個'MsgBox cell.Value'行'dateValue = cell.Value'?運行代碼,請告訴我們消息框顯示的是什麼 – 2013-07-25 14:24:38