我正在尝试编写一个应用程序,它需要一个报告(Excel 工作表),操作一行,然后转到下一行,然后是下一行,等等,然后在下一个中的前两个单元格中退出 Do Until 循环行为空(表示没有更多行要处理),如下所示:
Imports Excel = Microsoft.Office.Interop.Excel
Dim MSExcel As New Excel.Application
MSExcel.Visible = True
Dim WorkbookA As Excel.Workbook
Dim WorksheetA As Excel.Worksheet
Dim i As Integer = 2 'Skipping header row
Dim Split() As String
Dim SomeStrings() As String = {"StringA", "StringB"} 'etc... an array of strings
WorkbookA = MSExcel.Workbooks.Open(TextBox1.Text)
WorksheetA = WorkbookA.Sheets.Item(1)
Do Until WorksheetA.Cells(i, 1).Value = "" And WorksheetA.Cells(i, 2).Value = ""
'~~If Column A cell does not contain 'valueA' or Column E cell does not contain 'valueB', delete the row
Do Until InStr(WorksheetDisplay.Cells(i, 1).Value, "ValueA") <> 0 And InStr(WorksheetDisplay.Cells(i, 5).Value, "ValueB") <> 0 _
And InStr("somenumbershere", Strings.Left((WorksheetDisplay.Cells(i, 3).Value), 1)) <> 0 'Only keeps entries that begin with a certain number
WorksheetDisplay.Rows(i).Delete() 'Otherwise we delete the row
Loop
For Each Str As String In SomeStrings
If Str = WorksheetDisplay.Cells(i, 3).Value Then
Split = Strings.Split(WorksheetDisplay.Cells(i, 3).Value, " ")
WorksheetDisplay.Cells(i, 3).Value = Split(0) & " some text here"
End If
Next
i = i + 1
Loop
但是程序永远不会停止运行。
知道为什么吗?