vb使用excel中的一个有关问题

vb使用excel中的一个问题
VB6.0+excel2003 做一个简单的会议室安排座位的工具,做到这一步,与我计划中不一样,求解
无法贴图,用文字表述

排数 座位号 部门
1 1 aaaa
1 2 aaaa
1 3 aaaa
2 1 aaaa
2 2 aaaa
2 3 cccc
2 4 cccc
3 1 cccc
3 2 cccc
3 3 cccc
3 4 cccc

  表一

单位 人数 座位号(错) 我要的效果
aaaa 5 第 1排 1- 2 坐 第 1排 1- 3坐、第 2排 1- 2 坐
cccc 6 第 2排 3- 4 坐 第 2排 3- 4 坐、第 3排 1- 4 坐
  表二
我的代码:
Private Sub Command4_Click()
Dim i As Integer
Dim x As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim j As Integer
Dim k As Integer
j = xlsheet01.UsedRange.Rows.Count
k = xlsheet02.UsedRange.Rows.Count
i = 2
x = 2
For x = 2 To k
c = xlsheet01.Cells(i, 2)
d = xlsheet01.Cells(i, 1)
For i = i To j
 If xlsheet01.Cells(i, 3) <> xlsheet01.Cells(i + 1, 3) Then
   
  a = xlsheet01.Cells(i, 1)
  b = xlsheet01.Cells(i, 2)
  xlsheet02.Cells(x, 3) = "第" + Str(d) + "排" + Str(c) + "-" + Str(b) + " 坐"
  Exit For
 End If
Next i
i = i + 1
 Next x
End Sub

------解决方案--------------------
你这样首先得保证数据时连贯的啊 不然没有意义啊 
而且你是否还得按照部门等进行排序

否则如何保证能输出 1-3座位呢

你最好就是先遍历 插入到数组或者hash里面 

最后第二轮遍历hash根据需要的情况进行输出