English 中文(简体)
我怎么能够把我算在比照我的表日一栏。
原标题:How can I make my countif in Vba match just the month of my tables date column
  • 时间:2023-08-21 19:45:54
  •  标签:
  • excel
  • vba

当储存的距离值一栏与储存日期的月份和年份相匹配时,我试图做一些过滤的计算。

下面我知道,我无法将每月职能适用于第(1)栏,因为它要求有一系列内容。 I've尝试了将第(1)栏和第(3)栏与月份和年份相匹配的不同之处,但没有发现任何效果。

Public function(numcount(ByRef RDate As Date, Tal As range)

Counter =0
For i = 1 To tbl.rows.count
   If Month(tbl.cells(I,1).value) = month(RDate) and year(tbl.cells(I,1).value) = year(RDate) and tbl.cells(I,3) =“New” then
If worksheetfunction.countifts(tbl.columns(1) = month(Rdate), tbl.columns(1) = year(Rdate), tbl.columns(3), “New”, tbl.columns(11) tbl,cells(I,11) > 0 Then counter = counter + 1
End if
Next
End if
Numcount = counter
End function 
问题回答

Count Matches of Months in a Range of Dates (UDF)

Function MatchMonthsCount( _
    ByVal MatchRange As Range, _
    ByVal MatchDate As Date, _
    Optional ByVal CheckYear As Boolean = True) _
As Long

    Dim cell As Range, CellValue, mCount As Long, IsEqual As Boolean
    
    For Each cell In MatchRange.Cells
        CellValue = cell.Value
        If VarType(CellValue) = vbDate Then
            If Month(CellValue) = Month(MatchDate) Then
                If CheckYear Then
                    If Year(CellValue) = Year(MatchDate) Then IsEqual = True
                Else
                    IsEqual = True
                End If
            End If
            If IsEqual Then IsEqual = False: mCount = mCount + 1
        End If
    Next cell
    
    MatchMonthsCount = mCount

End Function

Figured it out! Took the month and year from the date and just checked if the date was between those two.

Countifs(Tbl.columns(1), “>=“& DateSerial(Year(Rdate), Month(Rdate), 1), tbl.columns(1), “<=“ & rdate, tbl.columns(1), …

在《守则》中将<代码>date强制令我工作到本月末。





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签