【发布时间】:2021-06-26 12:09:34
【问题描述】:
我正在寻找一个函数/宏,它可以在我的工作表的 A 列中找到下一个红色单元格。基本上我想做的是循环通过A列,每次我找到一个空单元格时,跳到下一个红色单元格并在那里继续循环。我只需要下一个红色单元格的行# 就可以了。到目前为止我的工作是这样的:
'Loop through column A from top down starting in row 6 and create Chart for each row
For rownumber = 6 To LastRow Step 1
'If Cell is filled
If TPsheet.Cells(rownumber, 1) <> "" Then
'Create Chart
Call CreateChart()
Else
rownumber = rownumber + 2 (This is the problem area, just going down 2 rows sadly doesnt work as sometimes there are 3/4/5 consecutive empty rows, need to set this to rownumber of next red cell)
End If
Next rownumber
整个表格如下所示: 并且不同的红色表格部分之间的空行数量可能会有所不同,这就是为什么当它找到一个空行时(我目前的方法)只向下走一定数量的行不起作用。
为了找到一个红细胞,我在另一个宏中成功使用了它:
Do Until i = 1000
If TPsheet.Range("A" & i).Interior.Color = RGB(255, 0, 0) Then
'...
End If
i = i + 1
Loop
TLDR:需要列a中下一个红色单元格的行号,当单元格为空时循环该列以跳转到下一个红色表头
【问题讨论】:
标签: excel vba loops find office365