問題已解決

老師,一個(gè)總 表怎么按業(yè)務(wù)員分成幾個(gè)分表

84784980| 提問時(shí)間:2019 12/04 21:10
溫馨提示:如果以上題目與您遇到的情況不符,可直接提問,隨時(shí)問隨時(shí)答
速問速答
成蹊老師
金牌答疑老師
職稱:注冊會計(jì)師,初級會計(jì)師,稅務(wù)師,中級會計(jì)師
點(diǎn)擊【開發(fā)工具】-【Visual Basic】或者Alt+F11的快捷鍵進(jìn)入VBE編輯界面。 插入一個(gè)新的模塊 粘貼下列代碼在模塊中: Sub CFGZB() Dim myRange As Variant Dim myArray Dim titleRange As Range Dim title As String Dim columnNum As Integer myRange = Application.InputBox(prompt:=請選擇標(biāo)題行:, Type:=8) myArray = WorksheetFunction.Transpose(myRange) Set titleRange = Application.InputBox(prompt:=請選擇拆分的表頭,必須是第一行,且為一個(gè)單元格,如:“姓名”, Type:=8) title = titleRange.Value columnNum = titleRange.Column Application.ScreenUpdating = False Application.DisplayAlerts = False Dim i&, Myr&, Arr, num& Dim d, k For i = Sheets.Count To 1 Step -1 If Sheets(i).Name <> 數(shù)據(jù)源 Then Sheets(i).Delete End If Next i Set d = CreateObject(Scripting.Dictionary) Myr = Worksheets(數(shù)據(jù)源).UsedRange.Rows.Count Arr = Worksheets(數(shù)據(jù)源).Range(Cells(2, columnNum), Cells(Myr, columnNum)) For i = 1 To UBound(Arr) d(Arr(i, 1)) = Next k = d.keys For i = 0 To UBound(k) Set conn = CreateObject(adodb.connection) conn.Open provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source= & ThisWorkbook.FullName Sql = select * from [數(shù)據(jù)源$] where & title & = & k(i) & Worksheets.Add after:=Sheets(Sheets.Count) With ActiveSheet .Name = k(i) For num = 1 To UBound(myArray) .Cells(1, num) = myArray(num, 1) Next num .Range(A2).CopyFromRecordset conn.Execute(Sql) End With Sheets(1).Select Sheets(1).Cells.Select Selection.Copy Worksheets(Sheets.Count).Activate ActiveSheet.Cells.Select Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False Next i conn.Close Set conn = Nothing Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub 插入一個(gè)控件按鈕,并指定宏到剛才插入的模塊代碼。 點(diǎn)擊插入的按鈕控件,根據(jù)提示選擇標(biāo)題行和要拆分的列字段
2019 12/04 21:37
描述你的問題,直接向老師提問
0/400
      提交問題

      您有一張限時(shí)會員卡待領(lǐng)取

      00:10:00

      免費(fèi)領(lǐng)取
      Hi,您好,我是基于人工智能技術(shù)的智能答疑助手,如果有什么問題可以直接問我呦~