我有一個包含一列一年用C柱d數據表,一個月B中柱,日,總數我得到類型不匹配錯誤
我試圖創建功能,總結一個月的今天來自d列的統計信息
Function countMessagesbyDate(xYear As Integer, xMonth As Integer, xDay As Integer) As Integer
Dim wsData As Worksheet
Dim LastRow As Long
Dim tMessages As Integer
Dim rowYear As Range
Dim rowMonth As Range
Dim rowDay As Range
Dim rowMessages As Range
Dim rCell As Range
Dim i As Integer
Application.ScreenUpdating = False
Set wsJData = ThisWorkbook.Sheets("daily_report")
Set rowYear = wsData.Range("A1").End(xlDown).Row
Set rowMonth = wsData.Range("B1").End(xlDown).Row
Set rowDay = wsData.Range("C1").End(xlDown).Rows
Set rowMessages = wsData.Range("D1:").End(xlDown).Rows
tMessages = 0
i = 0
For Each rCell In rowYear
i = i + 1
If rCell.Value = xYear And rowMonth.Offset(i) = xMonth And rowDay.Offset(i) < Day(Today) Then
tMessages = tMessages + rowMessages.Offset(i).Value
End If
Next rCell
countMessagesbyDate = tMessages
End Function
嘗試設置範圍時出現類型錯配。你能幫忙嗎?
在此先感謝
發佈錯誤請 –
如果您使用xlDown,我認爲您會得到很多行。它應該是xlRight嗎?或者更好的像wsData.Rows(1)一樣思考? –
請問哪一行?將'Option Explicit'放在模塊的頂部。它有助於。 –