For Each dr As DataRow In DataTables("表B").Select("第一列 > ''") Dim ii,i As Integer i = val(dr("第二列")) For Each fdr As DataRow In DataTables("表A").Select("第一列 = '" & dr("第一列") & "'","_SortKey") If i <= val(fdr("第二列")) fdr("第三列") = i Exit For Else fdr("第三列") = fdr("第二列") i -= val(fdr("第二列")) End If Next Next