|
sandy408 发表于 2012-12-5 15:09
亲,是按“门店”,不是按“部门”,完全看不懂,这方面是白痴啊,帮忙再改一下好不?谢谢鸟~~~
- Sub test()
- Dim dic As Object, i As Long, a
- Dim AWB As Workbook, BWB As Workbook
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False '关闭提醒
- On Error Resume Next
- Set AWB = ThisWorkbook
- Set dic = CreateObject("scripting.dictionary") '字典
- For i = 2 To Sheet1.Cells(Sheet1.Rows.Count, 2).End(xlUp).Row
- If Not dic.exists(Sheet1.Cells(i, 2) & "") Then dic.Add Sheet1.Cells(i, 2), "" '取不重复门店
- Next i
- a = dic.keys
- Set conn = CreateObject("adodb.connection")
- conn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0;hdr=yes';data source=" & ThisWorkbook.FullName
- For i = 0 To dic.Count - 1
- Sql = "select * from [" & Sheet1.Name & "$] where 门店='" & a(i) & "'"
- Set BWB = Workbooks.Add '新增工作簿
- ActiveWorkbook.SaveAs Filename:=AWB.Path & "" & a(i) & ".xlsx" '保存新增工作簿,文件名a(i)
- With BWB.Sheets(1)
- .UsedRange.Clear
- AWB.Sheets(1).Rows(1).Copy .Cells(1, 1) '表头
- .Cells(2, 1).CopyFromRecordset conn.Execute(Sql) '查询结果写入A2
- BWB.Save '保存
- BWB.Close '关闭
- End With
- Next i
- conn.Close
- Set conn = Nothing
- Set dic = Nothing
- Application.DisplayAlerts = True '开启提醒
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|