|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 录入()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet1")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a2:b" & rs)
End With
With Sheets("sheet2")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r = 1 And y = 1 Then
mm = ar(1, 2)
.[a2].Resize(UBound(ar), UBound(ar, 2)) = ar
Else
br = .Range(.Cells(2, 1), .Cells(r, y + 1))
For j = 2 To UBound(br, 2)
If Trim(br(1, j)) <> "" Then
d(Trim(br(1, j))) = j
End If
Next j
For i = 2 To UBound(br, 1)
If Trim(br(i, 1)) <> "" Then
d(Trim(br(i, 1))) = i
End If
Next i
lh = d(Trim(ar(1, 2)))
If lh = "" Then
lh = y + 1
Else
lh = lh
End If
br(1, lh) = ar(1, 2)
For i = 2 To UBound(ar, 1)
If Trim(ar(i, 2)) <> "" Then
If IsNumeric(ar(i, 2)) Then
xh = d(Trim(ar(i, 1)))
If xh <> "" Then
br(xh, lh) = br(xh, lh) + ar(i, 2)
End If
End If
End If
Next i
.Range(.Cells(2, 1), .Cells(r, y + 1)) = br
End If
End With
Set d = Nothing
MsgBox "ok!"
End Sub
|
|