简体   繁体   English

找到到达某个安装位置的单元 excel vba

[英]find the cells that reach to certain mount excel vba

there are multiple cells with numbers in a range.有多个单元格的数字在一个范围内。 I want to mark the cells which sum of them will reach to a certain number.我想标记它们的总和将达到一定数量的单元格。 For example: this code will find just two cells, but I need at least 30 cells例如:这段代码只会找到两个单元格,但我至少需要 30 个单元格

For each cell1 in range("A1:A30")
  For each cell2 in range("A1:A30")
    If cell1.value+cell2.value= MyNumber then
      Cell1.interior.color=vbRed
      Cell2.interior.color=vbRed
      Exit sub
    End if
  Next cell2
Next cell1

Thanks for helping me.谢谢你帮助我。

Try this;尝试这个; for range A1:A30, if cummulative sum reaches MyNumber, then will color red that range & exit the code...对于范围 A1:A30,如果累积总和达到 MyNumber,则将该范围涂成红色并退出代码...

Sub code()
MyNumber = 45
num = 0
For i = 1 To 30
    num = num + Range("A" & i).Value
    If num >= MyNumber Then
        Range("A1:A" & i).Interior.Color = vbRed
        Exit Sub
    End If
Next

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM