ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1775|回复: 2

[原创] 做的oracle-自动生成dataload导入模板

[复制链接]

TA的精华主题

TA的得分主题

发表于 2017-5-6 02:00 | 显示全部楼层 |阅读模式
本帖最后由 wt577 于 2017-5-6 02:05 编辑

主要做的实现研发费用-费用化转研发费用-资本化  模板的自动生成,然后通过dataload 软件导入到Oracle-ERP中

研发费用-费用化和研发费用-资本化  二级科目相同设置,是导入实现的关键。
根据每月资本化项目列表筛选出要资本化的条目,然后生成模板。


先加载加载宏。

Desktop.rar

154.96 KB, 下载次数: 29

414

TA的精华主题

TA的得分主题

 楼主| 发表于 2017-5-9 22:44 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
加入了字典写法

Private MaxRow2 As Integer, shtname As String

Sub data_Filter()
Dim Crng, MaxRow1 As Integer, Maxcol1 As Integer
        shtname = Application.InputBox("请输入Oracle明细账名称", "输入名称", "201704月明细账")
        ActiveSheet.Name = shtname
         Application.DisplayAlerts = False
        For Each wbsh In ActiveWorkbook.Sheets
              If wbsh.Name = "研发费用本月明细" Then
               wbsh.Delete
              End If
        Next
       MaxRow1 = ActiveSheet.[A1].CurrentRegion.Rows.Count
       Maxcol1 = ActiveSheet.[A1].CurrentRegion.Columns.Count
       MaxRow2 = MaxRow1 + 100
       Set Crng = Application.InputBox("条件单元格区域", "条件区域", "$I$901:$I$907", , , , , 8)
    ActiveSheet.[A1].Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Range(Selection, Selection.End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Crng, _
    CopyToRange:=Range("A" & MaxRow2), Unique:=False
    Sheets.Add.Name = "研发费用本月明细"
    Sheets(shtname).Select
    Range("A" & MaxRow2).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("研发费用本月明细").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
Sub Dataload()
            Dim Rowmax1 As Integer
            Dim Rowmax2 As Integer
            Dim Rowmax3 As Integer
            Dim I As Integer, J As Integer, m As Integer, R As Integer, W As Integer
            Dim Rowmax4 As Integer, Rowmax5 As Integer
            Dim wbsh As Worksheet
            Dim arr(1 To 10000, 1 To 16) As Variant
            Dim H As Integer
            Dim arr1(1 To 10000, 1 To 16) As Variant
            Application.ScreenUpdating = False
            Rowmax1 = ActiveSheet.Range("A1").CurrentRegion.Rows.Count
            Rowmax2 = Rowmax1 + 2
            Rowmax4 = Rowmax1 + 1
             Application.DisplayAlerts = False
                    For Each wbsh In ActiveWorkbook.Sheets
                      If wbsh.Name = "Dataload" Then
                       wbsh.Delete
                      End If
                    Next

            For I = 1 To Rowmax1
                    arr(I, 1) = Cells(I, 11) & "." & Cells(I, 12) & "." & Cells(I, 13) & "." & Cells(I, 15) & "." _
                               & Cells(I, 19) & "." & Cells(I, 20) & "." & Cells(I, 22) & "." & Cells(I, 23)
                    arr(I, 2) = "TAB"
                    arr(I, 3) = Cells(I, 27)
                    arr(I, 4) = "TAB"
                    arr(I, 5) = Cells(I, 7)
                    arr(I, 6) = "TAB"
                    arr(I, 7) = Cells(I, 31)
                    arr(I, 8) = arr(I, 6)
                    arr(I, 9) = Cells(I, 32)
                    arr(I, 10) = "TAB"
                    arr(I, 11) = Cells(I, 33)
                    arr(I, 12) = "TAB"
                    arr(I, 13) = Cells(I, 35)
                    arr(I, 14) = "TAB"
                    arr(I, 15) = Cells(I, 36)
                    arr(I, 16) = "ENT"
                    arr(1, 1) = "科目代码"
         Next I
                    Sheets.Add.Name = "Dataload"
                    ActiveSheet.[A1].Resize(Rowmax1, 16) = arr
                          Set dic = CreateObject("scripting.dictionary")
                            For J = 1 To Rowmax1
                                            If dic.exists(arr(J, 1)) Then
                                                     m = dic(arr(J, 1))
                                                    arr1(m, 3) = arr1(m, 3) + arr(J, 3)
                                            Else
                                                           k = k + 1
                                                          For u = 1 To UBound(arr, 2)
                                                                dic(arr(J, 1)) = k
                                                                arr1(k, u) = arr(J, u)
                                                          Next u
                                            End If
                             Next J
                         ActiveSheet.Range("A" & Rowmax2).Resize(Rowmax1, 16) = arr1

                          For R = 2 To Rowmax1
                           H = InStr(1, Cells(R, 1), 5301)
                           Cells(R, 1) = WorksheetFunction.Replace(Cells(R, 1), H, 6, 530101)
                         Next R
                         Rowmax3 = ActiveSheet.Range("A" & Rowmax2).CurrentRegion.Rows.Count
                         Rowmax5 = Rowmax2 + Rowmax3
                         For W = Rowmax2 + 1 To Rowmax5 - 1
                            Cells(W, 3) = -Cells(W, 3)
                         Next W

                Rows(Rowmax4 & ":" & Rowmax2).Select
                Selection.Delete Shift:=xlUp
                Columns("A:P").Select
                Columns("A:P").EntireColumn.AutoFit
                With Selection
                    .HorizontalAlignment = xlLeft
                    .VerticalAlignment = xlCenter
                    .WrapText = False
                    .Orientation = 0
                    .AddIndent = False
                    .IndentLevel = 0
                    .ShrinkToFit = False
                    .ReadingOrder = xlContext
                    .MergeCells = False
                End With
                Rows("2:2").Select
                ActiveWindow.FreezePanes = True
                 Sheets(shtname).Select
                    Rows(MaxRow2 & ":" & MaxRow2).Select
                    Range(Selection, Selection.End(xlDown)).Select
                    Selection.Delete Shift:=xlUp
                    Sheets("Dataload").Select
                    Application.DisplayAlerts = True
End Sub

Sub call_all()
Call data_Filter
Call Dataload

End Sub



TA的精华主题

TA的得分主题

 楼主| 发表于 2017-5-9 22:46 | 显示全部楼层
  1. Private MaxRow2 As Integer, shtname As String

  2. Sub data_Filter()
  3. Dim Crng, MaxRow1 As Integer, Maxcol1 As Integer
  4.         shtname = Application.InputBox("请输入Oracle明细账名称", "输入名称", "201704月明细账")
  5.         ActiveSheet.Name = shtname
  6.          Application.DisplayAlerts = False
  7.         For Each wbsh In ActiveWorkbook.Sheets
  8.               If wbsh.Name = "研发费用本月明细" Then
  9.                wbsh.Delete
  10.               End If
  11.         Next
  12.        MaxRow1 = ActiveSheet.[A1].CurrentRegion.Rows.Count
  13.        Maxcol1 = ActiveSheet.[A1].CurrentRegion.Columns.Count
  14.        MaxRow2 = MaxRow1 + 100
  15.        Set Crng = Application.InputBox("条件单元格区域", "条件区域", "$I$901:$I$907", , , , , 8)
  16.     ActiveSheet.[A1].Select
  17.     Range(Selection, Selection.End(xlToRight)).Select
  18.     Range(Selection, Selection.End(xlDown)).Select
  19.     Application.CutCopyMode = False
  20.     Range(Selection, Selection.End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Crng, _
  21.     CopyToRange:=Range("A" & MaxRow2), Unique:=False
  22.     Sheets.Add.Name = "研发费用本月明细"
  23.     Sheets(shtname).Select
  24.     Range("A" & MaxRow2).Select
  25.     Range(Selection, Selection.End(xlToRight)).Select
  26.     Range(Selection, Selection.End(xlDown)).Select
  27.     Selection.Copy
  28.     Sheets("研发费用本月明细").Select
  29.     Range("A1").Select
  30.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  31.         :=False, Transpose:=False
  32. End Sub
  33. Sub Dataload()
  34.             Dim Rowmax1 As Integer
  35.             Dim Rowmax2 As Integer
  36.             Dim Rowmax3 As Integer
  37.             Dim I As Integer, J As Integer, m As Integer, R As Integer, W As Integer
  38.             Dim Rowmax4 As Integer, Rowmax5 As Integer
  39.             Dim wbsh As Worksheet
  40.             Dim arr(1 To 10000, 1 To 16) As Variant
  41.             Dim H As Integer
  42.             Dim arr1(1 To 10000, 1 To 16) As Variant
  43.             Application.ScreenUpdating = False
  44.             Rowmax1 = ActiveSheet.Range("A1").CurrentRegion.Rows.Count
  45.             Rowmax2 = Rowmax1 + 2
  46.             Rowmax4 = Rowmax1 + 1
  47.              Application.DisplayAlerts = False
  48.                     For Each wbsh In ActiveWorkbook.Sheets
  49.                       If wbsh.Name = "Dataload" Then
  50.                        wbsh.Delete
  51.                       End If
  52.                     Next
  53.             
  54.             For I = 1 To Rowmax1
  55.                     arr(I, 1) = Cells(I, 11) & "." & Cells(I, 12) & "." & Cells(I, 13) & "." & Cells(I, 15) & "." _
  56.                                & Cells(I, 19) & "." & Cells(I, 20) & "." & Cells(I, 22) & "." & Cells(I, 23)
  57.                     arr(I, 2) = "TAB"
  58.                     arr(I, 3) = Cells(I, 27)
  59.                     arr(I, 4) = "TAB"
  60.                     arr(I, 5) = Cells(I, 7)
  61.                     arr(I, 6) = "TAB"
  62.                     arr(I, 7) = Cells(I, 31)
  63.                     arr(I, 8) = arr(I, 6)
  64.                     arr(I, 9) = Cells(I, 32)
  65.                     arr(I, 10) = "TAB"
  66.                     arr(I, 11) = Cells(I, 33)
  67.                     arr(I, 12) = "TAB"
  68.                     arr(I, 13) = Cells(I, 35)
  69.                     arr(I, 14) = "TAB"
  70.                     arr(I, 15) = Cells(I, 36)
  71.                     arr(I, 16) = "ENT"
  72.                     arr(1, 1) = "科目代码"
  73.          Next I
  74.                     Sheets.Add.Name = "Dataload"
  75.                     ActiveSheet.[A1].Resize(Rowmax1, 16) = arr
  76.                           Set dic = CreateObject("scripting.dictionary")
  77.                             For J = 1 To Rowmax1
  78.                                             If dic.exists(arr(J, 1)) Then
  79.                                                      m = dic(arr(J, 1))
  80.                                                     arr1(m, 3) = arr1(m, 3) + arr(J, 3)
  81.                                             Else
  82.                                                            k = k + 1
  83.                                                           For u = 1 To UBound(arr, 2)
  84.                                                                 dic(arr(J, 1)) = k
  85.                                                                 arr1(k, u) = arr(J, u)
  86.                                                           Next u
  87.                                             End If
  88.                              Next J
  89.                          ActiveSheet.Range("A" & Rowmax2).Resize(Rowmax1, 16) = arr1
  90.                        
  91.                           For R = 2 To Rowmax1
  92.                            H = InStr(1, Cells(R, 1), 5301)
  93.                            Cells(R, 1) = WorksheetFunction.Replace(Cells(R, 1), H, 6, 530101)
  94.                          Next R
  95.                          Rowmax3 = ActiveSheet.Range("A" & Rowmax2).CurrentRegion.Rows.Count
  96.                          Rowmax5 = Rowmax2 + Rowmax3
  97.                          For W = Rowmax2 + 1 To Rowmax5 - 1
  98.                             Cells(W, 3) = -Cells(W, 3)
  99.                          Next W
  100.                      
  101.                 Rows(Rowmax4 & ":" & Rowmax2).Select
  102.                 Selection.Delete Shift:=xlUp
  103.                 Columns("A:P").Select
  104.                 Columns("A:P").EntireColumn.AutoFit
  105.                 With Selection
  106.                     .HorizontalAlignment = xlLeft
  107.                     .VerticalAlignment = xlCenter
  108.                     .WrapText = False
  109.                     .Orientation = 0
  110.                     .AddIndent = False
  111.                     .IndentLevel = 0
  112.                     .ShrinkToFit = False
  113.                     .ReadingOrder = xlContext
  114.                     .MergeCells = False
  115.                 End With
  116.                 Rows("2:2").Select
  117.                 ActiveWindow.FreezePanes = True
  118.                  Sheets(shtname).Select
  119.                     Rows(MaxRow2 & ":" & MaxRow2).Select
  120.                     Range(Selection, Selection.End(xlDown)).Select
  121.                     Selection.Delete Shift:=xlUp
  122.                     Sheets("Dataload").Select
  123.                     Application.DisplayAlerts = True
  124. End Sub

  125. Sub call_all()
  126. Call data_Filter
  127. Call Dataload

  128. End Sub

复制代码
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-10-1 01:23 , Processed in 0.030577 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表