参考代码
Dim count As Integer = 1
Dim i As Integer = Format(1, "000")
Dim t As Table = Tables("汇总表")
t.Rows(0)("编号") = i
For j As Integer = 1 To t.rows.count-1
Dim pr As Row = t.Rows(j-1)
Dim cr As Row = t.Rows(j)
If cr("单位") <> pr("单位") Then
i += 1
count = 1
ElseIf cr("姓名") <> pr("姓名") Then
count = 1
i += 1
Else
count += 1
If count > 3 Then
count = 1
i += 1
End If
End If
cr("编号") = Format(i, "000")
Next