【问题标题】:Can VBA keep adding cells until the sum of those added cells are greater than another cell value?VBA 可以继续添加单元格,直到这些添加的单元格的总和大于另一个单元格值?
【发布时间】:2021-07-15 17:55:08
【问题描述】:

我需要继续在列 (B) 中添加单元格,直到这些添加值的总和等于或大于另一个单元格值。然后隐藏未添加的行。

图片通过 Stacks Overflows 图片软件 IMGUR 附上。

感谢任何信息或方向!

【问题讨论】:

  • 如果添加行直到总和等于 C 列中的值,为什么会有额外的行?了解起点是什么可能会有所帮助。此外,您目前拥有的任何代码都可以让我们避免重做已经存在的代码
  • “然后隐藏未添加的行”应该是什么意思?

标签: excel vba


【解决方案1】:

试试这个 VBA 程序。

Option Explicit

Sub HideExtraRows()
Dim PartRange As Range, cl As Range, PartTxt As String
Dim BOQty As Double, POQty As Double
PartTxt = ""

On Error Resume Next
Set PartRange = Application.InputBox("Select the Parts Range to hide extra rows", _
                "Select Range", , , , , , 8)
If PartRange Is Nothing Then Exit Sub
On Error GoTo 0

For Each cl In PartRange
    If cl <> PartTxt Then
        PartTxt = cl
        BOQty = cl.Offset(, 2)
        POQty = cl.Offset(, 1)
    Else
        POQty = POQty + cl.Offset(, 1)
        If POQty > BOQty Then cl.EntireRow.Hidden = True
    End If
Next cl

End Sub

【讨论】:

  • 这很好用!!你如何擅长 VBA?我一直在做 youtube 视频和教程,但还不足以完成这个程序。对初学者有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-28
  • 2018-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多