由于我为公式引用了单元格的方式,这变得非常复杂 . 第一,第二,第三和第四范围参考动态小区位置 . 这是我遇到问题的代码 .
Dim first As Range
Dim second As Range
Dim third As Range
Dim fourth As Range
Dim i As Long
Dim k As Long
For i = 0 To -170
For k = 0 To 170
Set first = ws.Rows(3 + k).Cells.Find("QQQ").Offset(0 + i, -12)
Set second = ws.Rows(3 + k).Cells.Find("QQQ").Offset(0 + i, -11)
Set third = ws.Rows(3 + k).Cells.Find("QQQ").Offset(0 + i, -8)
Set forth = ws.Rows(3 + k).Cells.Find("QQQ").Offset(0 + i, -7)
ws.Rows(3 + k).Cells.Find("QQQ").Offset(0, -6).Formula = "=IF(OR(AND(first<(third-0.33),first<>0,first<1.33),AND(second<(forth-0.33),second<>0,second<1.33)),TRUE,FALSE)"
Next k
Next i
它没有出现任何错误和运行,但在工作表上找不到公式 . 它旨在为我的每一行数据运行我的公式 . 它在我指定的列中放置true或false值 . 谁能看出我做错了什么?谢谢 .
这是文件 . 宏被分配到 Capability Report
工作表上的按钮 . 宏的名称是button_click 7 .
https://drive.google.com/open?id=0B-Cnpvgoos3cTzQ4dVRpMHJ1Zjg
宏不会运行,因为它引用了我的驱动器,但至少你可以查看报告 .
编辑:这是新代码 . 请参阅下面的评论,看看发生了什么 .
Dim first As Range
Dim second As Range
Dim third As Range
Dim fourth As Range
Dim i As Long
Dim k As Long
For i = 0 To 167
Set first = ws.Rows(169 - i).Cells.Find("QQQ").Offset(0 + i, -12)
Set second = ws.Rows(169 - i).Cells.Find("QQQ").Offset(0 + i, -11)
Set third = ws.Rows(169 - i).Cells.Find("QQQ").Offset(0 + i, -8)
Set forth = ws.Rows(169 - i).Cells.Find("QQQ").Offset(0 + i, -7)
ws.Rows(169 - i).Cells.Find("QQQ").Offset(0, -6).Formula = "=IF(OR(AND(" & first.Address & "<(" & third.Address & "-0.33)," & first.Address & "<>0," & first.Address & "<1.33),AND(" & second.Address & "<(" & forth.Address & "-0.33)," & second.Address & "<>0," & second.Address & "<1.33)),TRUE,FALSE)"
Next i
1 回答
好的,所以我想通了 . 关闭我的上次更新,需要
first
代码和.Address
代码,以使该字首先成为一个位置而不是文本 . 我遇到的另一个问题是涉及i
的My Formulas错了 . 这是一个更新的代码 .