簡體   English   中英

VBA 可以繼續添加單元格,直到這些添加的單元格的總和大於另一個單元格值嗎?

[英]Can VBA keep adding cells until the sum of those added cells are greater than another cell value?

我需要繼續在列 (B) 中添加單元格,直到這些添加值的總和等於或大於另一個單元格值。 然后隱藏尚未添加的行。

圖片通過 Stacks Overflows 圖片軟件 IMGUR 附上。

感謝任何信息或方向!

https://i.stack.imgur.com/PrthL.png

試試這個 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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM