Excel VBA – 循环无法正确导入数据

我有一段代码可以从HTML应用程序中提取客户交易数据,并将其添加到一起,然后将这些数字导入电子表格。 代码在表单上循环显示客户帐号列表,但是我在导入到电子表格中的数据时遇到了问题。 而不是导入数据,然后循环到下一个帐户,似乎循环通过每个帐户,导入所有帐户的总数,而不是每个帐户的总数。 希望这是有道理的,下面是我认为导致问题的代码部分,我只是不确定是否需要用循环调整某些东西,或者是导致问题的“.Value”。 我将不胜感激任何build议/帮助,我可以得到。

Dim lastRow As Integer lastRow = Cells(10000, 6).End(xlUp).Row rowData = 6 'set it to the first row of player account data dblTotalSlot = 0 dblTotalTable = 0 For x = rowData To lastRow ' Navigate to Search screen IE.navigate my_url2 If Not IEWait(IE) Then GoTo EndMe End If 'check to see if user was successfully logged in If Not IE.LocationURL Like "*search*" Then 'couldn't find the word 'Search' in the url, so it didn't make it here for some reason MsgBox "Please check your username/password is correct and try again.", vbCritical, "Error" GoTo EndMe End If IE.document.getElementById("accountNumber").Value = Me.Cells(x, 6).Value 'use the rowdata variable to get which row we are at IE.document.getElementById("action").Click If Not IEWait(IE) Then GoTo EndMe End If IE.navigate my_url3 If Not IEWait(IE) Then GoTo EndMe End If IE.document.getElementById("site").Value = Me.Cells(7, 4).Value IE.document.getElementById("action").Click If Not IEWait(IE) Then GoTo EndMe End If dblCustomerTTotal = 0 dblCustomerSTotal = 0 For i = 1 To 1 Set TDelements = IE.document.getElementsByTagName("tr") For Each TDelement In TDelements If TDelement.className = "searchActivityResultsCustomerTContent" Then dblCustomerTTotal = dblCustomerTTotal + VBA.CDbl(TDelement.ChildNodes(8).innerText) ElseIf TDelement.className = "searchActivityResultsCustomerSContent" Then dblCustomerSTotal = dblCustomerSTotal + VBA.CDbl(TDelement.ChildNodes(8).innerText) End If Next Set elems = IE.document.getElementsByTagName("input") For Each e In elems If e.Value = "Next Results" Then e.Click If Not IEWait(IE) Then GoTo EndMe End If i = 0 Exit For End If Next e Next i Me.Cells(rowData, 7).Value = dblCustomerTTotal Me.Cells(rowData, 8).Value = dblCustomerSTotal Me.Cells(rowData, 9).Value = dblCustopmerTTotal + dblCustomerSTotal dblTotalT = dblTotalT + dblCustomerTTotal dblTotalS = dblTotalS + dblCustomerSTotal Next x EndMe: IE.Quit Application.ScreenUpdating = True On Error GoTo 0 'reset the error handler End Sub