|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
新增刚刚修改了一下,如果员工编号已经在数据库里,就不增加的
- Sub 新增()
- Set sh1 = ThisWorkbook.Sheets("表2")
- If sh1.[d5] = "" Then Exit Sub
- Application.DisplayAlerts = 0
- f = ThisWorkbook.Path & "\数据.xls"
- Set wb = Workbooks.Open(f, 0)
- Set sht = wb.Sheets("表1")
- Set d = CreateObject("scripting.dictionary")
- rr = sht.Cells(Rows.Count, 2).End(3).Row
- arr = sht.Range("b5:n" & rr)
- For i = 1 To UBound(arr)
- d(arr(i, 3)) = arr(i, 3)
- Next
- If Not d.exists(sh1.[d5].Value) Then
- sh1.Range("b5:n5").Copy sht.Range("b" & rr + 1)
- With sht.Range("b" & rr + 1).Resize(1, 13)
- .Font.Color = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .Font.Size = 10
- .Font.Bold = False
- .Borders.LineStyle = 1
- End With
- Else
- MsgBox "数据库已经有了,不需要加入!!"
- End If
- wb.Save
- wb.Close 0
- Application.DisplayAlerts = 1
- Beep
- End Sub
复制代码 |
|