我正在尝试获得某个表设置,但是当我第一次启动它时,我没有意识到这将是一个糟糕的设置。我的许多同事已经使用过它,但我需要帮助为我的excel制作一个公式。
我并尝试合并:
SUMPRODUCT(A3:Q3,--(MOD(COLUMN(A3:Q3),3)=0))
获得第三列的总和:
=SUMIFS(A3:Q3,A1:Q1,">="&F1+1,A1:Q1,"<="&Q1)
我试图找到两个日期之间的总和。
我没有很多数学与excel,我似乎无法让它工作。有帮助吗?我很擅长表示对不起。
答案 0 :(得分:0)
此自定义函数将执行您想要的操作。它说明了任何情况下的基本方法。按Alt + F11打开VBA编辑器(VBIDE),右键单击&#34;模块&#34;创建一个新模块。编辑器中的文件夹(使用视图菜单确保项目资源管理器已打开),并复制并粘贴以下内容。您应自行调试,以便通过设置断点或创建调用来查看它正在执行的操作sub(示例在底部),以便您可以使用F8
单步执行Option Explicit
Public Function THIRDCOLUMNDATESUM(ByVal colStart As Long, ByVal colEnd As Long, _
ByVal DateMin As Date, ByVal DateMax As Date) As Double
'returns a long sum of the numerical values in row three of every third column
'it checks to ensure that the date (at the top of the column) is between
'the two passed dates (DateMin and DateMax)
'Allocate for a long counter and a Double sum (in case you are working with decimals)
Dim i As Long, sum As Double
'for each column between colStart and colEnd
For i = colStart To colEnd
'if it's the first column, or in a column divisible by three with no remainder
If (i = 1) Or (i Mod 3 = 0) Then
'And the date in the column header (row 1) is between (but not equal to)
'DateMin and DateMax
If ActiveSheet.Cells(1, i) > DateMin And ActiveSheet.Cells(1, i) < DateMax Then
'add the numerical value in row 3 of that column to the sum
sum = sum + ActiveSheet.Cells(3, i).Value
End If
End If
'next column
Next i
THIRDCOLUMNDATESUM = sum
End Function
示例测试子
Sub Test()
THIRDCOLUMNDATESUM 1, 18, "15/1/1950", "15/01/2015"
End Sub
只需输入以下内容即可在工作表单元格中使用它:
=THIRDCOLUMNDATESUM(1, 21, A1, F1)
假设您想要的日期作为边界在单元格A1和F1中,并且您只想查看列A - U
答案 1 :(得分:0)
我并尝试合并:
SUMPRODUCT(A3:Q3,--(MOD(COLUMN(A3:Q3),3)=0))
获得第三列的总和:
=SUMIFS(A3:Q3,A1:Q1,">="&F1+1,A1:Q1,"<="&Q1)
要合并这些,只需在SUMPRODUCT
的末尾添加额外的要求作为附加数组,例如:
=SUMPRODUCT(A3:Q3,--(MOD(COLUMN(A3:Q3),3)=0),--(A1:Q1>=(F1+1)),--(A1:Q1<=Q1))