搞不懂你什么逻辑
Dim names As New List(Of String)
Dim names2 As New List(Of String)
For i As Integer = 0 To Tables("开具piao据").Rows.Count-1
names.Add(Tables("开具piao据").Rows(i)("收购凭证号"))
names2.Add(Tables("开具piao据").Rows(i)("收购凭证号"))
Next
Dim n As Integer = 0
Dim a As Integer = 0
For Each name As String In names2
Dim nn As String
nn = name + 1
nn = format(CInt(nn),"000000000")
If Names.Contains(nn)= True Then
n = n + 1
Continue For
Else
Sheet1(5+a,3).Value = format(CInt(name),"000000000")
Sheet1(5+a,1).Value = Sheet1(5,3).Value - n
Sheet1(5+a,1).Value = format(CInt(Sheet1(5+a,1).Value),"000000000")
Sheet1(5+a,5).Value = DataTables("开具piao据").Compute("count([收购凭证号])", "收购凭证号 >= " & Sheet1(5,1).Value & " and 收购凭证号 <= " & Sheet1(5,3).Value & " and 作废 = false")
Sheet1(5+a,6).Value = DataTables("开具piao据").Compute("count([收购凭证号])", "收购凭证号 >= " & Sheet1(5,1).Value & " and 收购凭证号 <= " & Sheet1(5,3).Value & " and 作废 = true")
n = 0
a = a + 1
End If
Names.Remove(name)
Next