excel - 循环执行错误

标签 excel vba compiler-errors do-while

我试图遍历三个数据列表并隐藏总值为0的行。尽管我不断收到“Loop Without Do”错误,但是有人可以发现我做错了什么。

干杯。

Sub Button1_Click()

Dim Brow1 As Integer
Dim Brow2 As Integer
Dim Brow3 As Integer

Dim Trow1 As Integer
Dim Trow2 As Integer
Dim Trow3 As Integer

Brow1 = 62
Trow1 = 3
Brow2 = 126
Trow2 = 67
Brow3 = 190
Trow3 = 131

Do While Brow1 > Trow1

    If Range("P" & Brow1).Value = 0 Then
        Rows(Brow1).EntireRow.Hidden = True

    ElseIf Range("P" & Brow1).Value <> 0 Then

       Brow1 = Brow1 - 1
Loop


Do While Brow2 > Trow2

    If Range("P" & Brow2).Value = 0 Then
        Rows(Brow2).EntireRow.Hidden = True

    ElseIf Range("P" & Brow2).Value <> 0 Then
       Brow2 = Brow2 - 1
Loop

Do While Brow3 > Trow3

    If Range("P" & Brow3).Value = 0 Then
        Rows(Brow3).EntireRow.Hidden = True

    ElseIf Range("P" & Brow3).Value <> 0 Then
       Brow3 = Brow3 - 1
Loop

End Sub

最佳答案

您的If语句均未正确关闭。在每个“ElseIF”之后添加“End If”,您应该会得到预期的行为:

Do While Brow1 > Trow1

    If Range("P" & Brow1).Value = 0 Then
        Rows(Brow1).EntireRow.Hidden = True

    ElseIf Range("P" & Brow1).Value <> 0 Then

       Brow1 = Brow1 - 1
    End If
Loop

关于excel - 循环执行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31058833/

相关文章:

excel - 将 SHA-256 库移植到 Excel

mysql - VBA 错误 :`[Microsoft][ODBC Manager] Data source name not found and no default driver specified

ios - xcode 7 + 核心数据 : cannot import module being compiled

android - android不断给我的应用这个错误:addView(View, LayoutParams) is not supported

vba - 在 VBA 中将单词转换为数字

c - 在 ubuntu 中编译 c 程序时出错 "storage size of time_struct isn' t know"

excel - 使用 VBA 将 Excel (2016) 文件中的图片导出为 gif 最终出现黑屏

xml - 如何在R中打开文件格式和文件扩展名不同的excel文件?

Python Pandas Vlookup

c++ - 通过 C++ DLL 将 Arduino 字符串转换为 Excel BSTR 的随机字符