gpt4 book ai didi

excel - 循环执行错误

转载 作者:行者123 更新时间:2023-12-02 10:50:27 25 4
gpt4 key购买 nike

我试图遍历三个数据列表并隐藏总值为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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com