|
Sub test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Index > 6 Then sh.Delete
Next sh
Application.DisplayAlerts = True
ar = Sheets("水费").[a1].CurrentRegion
For i = 3 To UBound(ar)
If Len(Trim(ar(i, 1))) <> 0 Then
Sheets("模板").Copy after:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.Name = ar(i, 1)
Set Rng = Sheets("饮用水").Columns(1).Find(ar(i, 1), , , 1)
If Not Rng Is Nothing Then
r = Rng.Row
.Cells(6, 2) = Sheets("饮用水").Cells(r, 3)
.Cells(6, 3) = Sheets("饮用水").Cells(r, 2)
.Cells(6, 4) = Sheets("饮用水").Cells(r, 4)
End If
Set Rng = Nothing
Set Rng = Sheets("电费").Columns(6).Find(ar(i, 1), , , 1)
If Not Rng Is Nothing Then
r = Rng.Row
.Cells(7, 4) = Sheets("电费").Cells(r, 13)
End If
Set Rng = Nothing
Set Rng = Sheets("水费").Columns(1).Find(ar(i, 1), , , 1)
If Not Rng Is Nothing Then
r = Rng.Row
.Cells(8, 4) = Sheets("水费").Cells(r, 6)
End If
Set Rng = Nothing
Set Rng = Sheets("房租").Columns(2).Find(ar(i, 1), , , 1)
If Not Rng Is Nothing Then
r = Rng.Row
.Cells(9, 4) = Sheets("房租").Cells(r, 4)
End If
Set Rng = Nothing
Set Rng = Sheets("用餐人数").Columns(1).Find(ar(i, 1), , , 1)
If Not Rng Is Nothing Then
r = Rng.Row
.Cells(14, 3) = Sheets("用餐人数").Cells(r, 37)
.Cells(15, 3) = Sheets("用餐人数").Cells(r, 38)
End If
Set Rng = Nothing
End With
End If
Next i
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|