|
当我查退费时只查到一条记录,明明里面有两条记录啊,以下为查询代码
Private Sub CommandButton1_Click()
Sheets("费用查询结果表").Rows("2:9999").ClearContents '清除之前的筛选结果
Sheets("费用查询结果表").Visible = True
Sheets("费用查询结果表").Activate
For i = 0 To 费用项目.ListCount - 1
If 费用项目.Selected(i) Then '如果项目被选择
With Sheets("费用记录")
Set rng = .Rows(1).Find(费用项目.List(i), , , xlWhole) '查找到项目所在单元格
Set rng1 = .Rows(1).Find(费用项目.List(i), , , xlWhole) '同上,赋给另一个变量
Do Until rng.End(xlDown).Value = "" '向下定位到的单元格为空则退出
Set erng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) '定位复制到的目标单元格位置
Set rng = rng.End(xlDown) '将单元格定位后向赋给自己
rng.EntireRow.Range("a1:c1").Copy erng
erng.Offset(0, 3) = rng1
erng.Offset(0, 4) = rng
erng.Offset(0, 5) = rng.EntireRow.Range("l1")
rng.EntireRow.Range("m1:p1").Copy erng.Offset(0, 6)
Loop
End With
End If
Next
End Sub
Private Sub UserForm_Initialize()
For Each a In Array("保教费", "接送费", "伙食费", "退费", "被子", "书包", "校服")
Me.费用项目.AddItem a
Next
End Sub
|
|