根据单元格值VBA Excel隐藏行

时间:2014-06-08 22:11:50

标签: excel excel-vba vba

我有一份摊还表,列出了每日余额,但付款是每月进行的,所以有很多天付款都是0美元。 我正在尝试构建一个宏,它将从第17行一直到我的最后一行选择整行。我只希望它选择当天付款(第4栏)为0的行。想法?

我让它以一种方式做到但它确实很慢,因为它逐个检查行。有超过3000行可供查看。

  'Only for Debt Consolidator

'The goal of this macro is to select the "Empty payments" rows and hide them
'It works but I need to select all the rows first and then hide them otherwise
'It takes far too long.

Sub Hide()

  Dim X As Integer
  Dim Last As Integer

   'Needed
   Last = Application.WorksheetFunction.Max(Sheets("Debt Consolidator").Range("A16:A100000"))

'Needed

For X = 17 To Last
    'Needed
    If Cells(X, 4) = 0 Then
    Rows(X).Hidden = True

        'Lists as a percentage to show the progress of the Macro
        Range("L15") = (X - 17) / Last
    Else

    Rows(X).Hidden = False

    End If
        'Needed
        'Hides the selected Row(s)
        'selection.EntireRow.Hidden = True
Next

Range("L15") = Empty
MsgBox "Complete"

End Sub

0 个答案:

没有答案