“没有循环”错误

时间:2015-10-29 16:32:34

标签: excel vba

这个子程序运行良好,但现在我得到一个“Loop without Do”错误:

Sub Upload_earned_pto()

Dim conn As New ADODB.Connection
Dim iRowNo As Integer
Dim UID, PW, s1, s3, s5, s7 As String
Dim s4, s6 As Date
Dim s2 As Double


UID = ThisWorkbook.Sheets("Sheet1").Range("A1")
PW = ThisWorkbook.Sheets("Sheet1").Range("B1")


With Sheets("Monthly Adjustments")

    'Open a connection to SQL Server
    conn.Open "Provider=SQLOLEDB.1;Password=" & PW & ";Persist Security Info=True;User ID=" & UID & ";Initial Catalog=TESTDB;Data Source=TESTSRV;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=MPL-DEV1;Use Encryption for Data=False;Tag with column collation when possible=False"

    'Skip the header row
    iRowNo = 8

    'Loop until empty cell in batch_skey
    Do Until .Cells(iRowNo, 1) = ""
        If Rows(iRowNo).Hidden = True Then
            iRowNo = iRowNo + 1
        ElseIf Rows(iRowNo).Hidden <> True Then

        s1 = .Cells(iRowNo, 1)
        s2 = .Cells(iRowNo, 2)
        s3 = .Cells(iRowNo, 3)
        s4 = .Cells(iRowNo, 4)
        s5 = .Cells(iRowNo, 5)
        s6 = .Cells(iRowNo, 6)
        s7 = .Cells(iRowNo, 7)

'Generate and execute sql statement to export the excel rows to SQL Server table
conn.Execute "insert into dbo.pto_transactions values ('" & s1 & "', '" & s3 & "'

, '" & s6 & "', '" & s2 & "', '" & s4 & "', '" & s5 & "', '" & s7 & "')"
        iRowNo = iRowNo + 1
    Loop

    MsgBox "PTO Transactions Successfully Sent."

    conn.Close
    Set conn = Nothing

End With

1 个答案:

答案 0 :(得分:0)

错过结束如果。感谢@ScottCraner指出它。