6楼的代码,在Table("表A").Filter = "" 的时候,会报错。
稍改一下:
Dim ss As List(of String) = DataTables("表A").GetValues("项目", Tables("表A").Filter)
Dim flt As String
If Tables("表A").Filter > "" Then
flt = " And " & Tables("表A").Filter
Else
flt = ""
End If
For Each s As String In ss
Dim drs As List(Of DataRow) = DataTables("表A").Select("项目 = '" & s & "'" & flt,"单位")
drs(0)("预赛组别") = 1
For i As Integer = 1 To drs.Count - 1
Dim i1 As Integer = drs(i - 1)("预赛组别")
If i1 >= Math.Ceiling(drs.Count / 8)
For i2 As Integer = 1 To 8
Dim i3 As Integer = DataTables("表A").Compute("Count(项目)","项目 = '" & s & "' and 预赛组别 = '" & i2 & "'" & flt)
If i3 < Math.Ceiling(drs.Count / 8)
drs(i)("预赛组别") = 1
Else
drs(i)("预赛组别") = i3
End If
Next
Else
drs(i)("预赛组别") = i1 + 1
End If
Next
Next
For Each s As String In ss
Dim ss1 As List(of String) = DataTables("表A").GetValues("预赛组别","项目 = '" & s & "'" & flt)
For Each s1 As Integer In ss1
Dim drs As List(of DataRow) = DataTables("表A").Select("项目 = '" & s & "'and 预赛组别='" & s1 & "'" & flt,"单位")
drs(0)("预赛道次") = 1
For i As Integer = 1 To drs.Count - 1
drs(i)("预赛道次") = drs(i - 1)("预赛道次") + 1
Next
For i As Integer = 1 To drs.Count - 1
If drs(i)("单位") = drs(i - 1)("单位")
If (i - 4)>=0
drs(i)("预赛道次") = i - 4 + 1
drs(i - 4)("预赛道次") = i + 1
ElseIf (i + 4) <= drs.Count
drs(i)("预赛道次") = i + 4 + 1
drs(i + 4)("预赛道次") = i + 1
End If
End If
Next
Next
Next
Tables("表A").Sort = "项目,预赛组别,预赛道次"