为什么这段代码会循环?

时间:2016-04-19 23:52:49

标签: vba

我们陷入了循环,无法让它继续拉动值。这段代码只会拉出第一个值并保持循环。

Sub createpbp()

    Dim iRows As Integer
    Dim i As Integer 'webtext row counter
    Dim iR As Integer
    Dim iPr As Integer 'row counter for pbp worksheet
    Dim wksWT As Worksheet


    iPr = 1

    Set wksWT = Worksheets("Webtext") 'creating a variable for the text pulled from website

    wksWT.Activate 'activate the webtext sheet

    iRows = wksWT.UsedRange.rows.Count 'counts rows in the play by play

    For i = 1 To iRows 'row 1 to end of rows
        If Cells(i, 1) = "Play By Play Innings" Then 'if the cell value says play by play innings
            Do Until Cells(i, 1) = "Runs" 'continue doing the following until reach end of inning
                Cells(i, 1).Copy 'copy the value of the first event in inning
                Sheets("Play by Play text").Select 'open up new worksheet
                If Cells(iPr, 1) = Null Then
                    Cells(iPr, 1).Paste
                Else
                    iPr = iPr + 1
                End If
            Loop
        End If
    Next i

1 个答案:

答案 0 :(得分:1)

你的循环有些不对劲。

Do Until Cells(i, 1) = "Runs"

我没有看到你的循环中的任何地方将此单元格的值更改为“运行”。我没有看到你的循环中的任何地方增加了i的值。