|
Sub 录入()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 3).End(xlUp).Row
If r < 4 Then MsgBox "请输入数据!": End
ar = .Range("c4:d" & r)
rq = .[c2]
End With
With Sheet2
rs = .Cells(Rows.Count, 2).End(xlUp).Row + 1
y = .Cells(2, Columns.Count).End(xlToLeft).Column
br = .Range(.Cells(2, 2), .Cells(rs, y))
For j = 2 To UBound(br, 2)
If Trim(br(1, j)) <> "" Then
d(Trim(br(1, j))) = j
End If
Next j
xh = UBound(br)
For i = 1 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
lh = d(Trim(ar(i, 1)))
If lh <> "" Then
br(xh, lh) = ar(i, 2)
End If
End If
Next i
br(xh, 1) = rq
.Range(.Cells(2, 2), .Cells(rs, y)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|