【发布时间】:2017-09-10 18:16:10
【问题描述】:
我正在尝试迭代一个表并从位置 A(A 列)处的单元格(日期单元格)等于某个日期的所有行获取索引,我从另一个单元格获取的日期可以说是 H1 单元格。单击时,我有一个带有附加宏的按钮。
该表有 10000 多行,有 7 列(A、B、C、D、E、F、G)
A 列代表日期。在javascript中它会是这样的。
A 列内的所有单元格都有日/月/年值。整张桌子只有一年。所以表格从 2017 年 1 月 1 日开始,到 2017 年 12 月 31 日结束。
const myDate = worksheet.getCell('H1').Value;
const columnA = worksheet.getColumns('A') // here i use pseudocode
columnA.forEach((cell, index) => {
if (cell.Value == myDate)
console.log(index); // instead i can push each index in array so later i could forEach the rows with these indexes and then do some manipulation.
});
我的任务基本上是将日期字符串放入 H1 单元格。并且当单击按钮时,必须打印第一个单元格(列 A )等于 H1 单元格的所有行。
已编辑:
到目前为止已经尝试过了,我正在存储和索引一天的开始和结束的位置。所以我有范围。现在如何选择所有行在 firstRow 和 lastRow 之间的单元格并将它们打印出来。
Sub FindMyNubmer()
Dim a As Range, b As Range
Dim firstRow As Long
Dim lastRow As Long
Set a = Range("A1:A65000")
For Each b In a.Rows
If b.Value = Range("H4").Value Then
If firstRow = "0" Then
firstRow = b.Row
End If
lastRow = b.Row
End If
Next
MsgBox firstRow & " - " & lastRow
End Sub
【问题讨论】: