excel - 如何使此函数遍历两个范围?
问题描述
所以我一直在尝试构建一个函数来使用For loop
=IFERROR(IF(AND(N$10>=PivotTabel!$L5;N$10<=PivotTabel!$M5);"1";"0.5");"X") &
IF(AND(N$10>=Sheet1!$L125;N$10<=Sheet1!$M125);"yes";"n") &
IF(AND(N$10>=Sheet1!$L126;N$10<=Sheet1!$M126);"yes";"n") &
IF(AND(N$10>=Sheet1!$L127;N$10<=Sheet1!$M127);"yes";"n")
此公式用于检查日期是否在日期期间之间(例如检查 01.01.2020 是否在 02.08.2019 和 20.02.2020 之间,如果在第一种情况下为真,我打印“1”,其他情况下我打印“是” )。正如您在上面看到的,我需要在 VBA 中编写的公式来遍历指定数量的单元格,其中一列是 $L125: $L139,另一列是$M125:$M139
我写了下面的函数,但它给了我#VALUE!
Function Date_Increment(MaxCount As Integer) As String
' This function does incrementation of date ranges
Dim Result As String
Static i As Integer
i = 125
Dim cell As Range
'MaxCount is the number times to iterate just to test
'My idea is to use the function COUNT("L125:L139") to return the number of cells that are not blank
For Each i In MaxCount
' this is the cell i want to run formula in
Range("GUI!D12").Formula = "=IFERROR(IF(AND(D$10>=PivotTabel!$L5;D$10<=PivotTabel!$M5);""1"";""0.5"");""X"") & IF(AND(D$10>=Sheet1!$L" & i & ";D$10<=Sheet1!$M" & i & ");""yes"";""n"")"
Result = Range("GUI!D12").Formula
i = i + 1
Next cell
'Next j
DateRange_Increment
End Function
我的问题是:如何让这个函数遍历两个范围?或者,如果有一个仅使用公式的简单解决方案,我也会使用它。另外请检查我的功能是否有错误。
任何帮助我都会非常感激。
解决方案
推荐阅读
- macos - 将多个文件中的姓氏grep到多个子目录
- tensorflow - 如何重塑一维 CNN 的数据集?
- c++ - 如何用-1全局初始化二维数组?
- react-native - 使用 Axios GET POST 的 Twitch API 出现问题
- c# - 在旧版非 MEF 组件中使用 Visual Studio 编辑器服务
- reactjs - React,Firebase - signInWithEmailAndPassword - 不能在 .then() 块之外使用用户变量
- html - HTML 模型查看器始终允许即时交互在移动设备上不起作用
- sre - 谷歌如何运行生产系统——SRE 的“50% 的项目工作时间”到底是什么?
- google-my-business-api - 查找 Google My Business API 请求的来源
- c# - 类列表对象的方法