0
我想迭代一個表並獲取所有行的位置A(列A)的單元格(單元格)等於某個日期,我從另一個單元獲得的日期讓我說H1
單元格。點擊時,我有一個附帶宏的按鈕。 該表有超過10000行,並有7列(A,B,C,D,E,F,G) A列表示日期。在JavaScript中它會是這樣的東西。VBA excel宏迭代一個表,並選擇列A行中的行單元格的所有行
A列內的所有單元格都有日/月/年的值。整個桌子只有一年。所以表格從01/01/2017開始,並將於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