ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 求助一个关于自动结转损益的代码

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-11-13 17:07 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
各位老师好,求一段自动结转损益的代码。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-14 22:35 | 显示全部楼层
没人顶啊,我自己顶

TA的精华主题

TA的得分主题

发表于 2019-11-18 16:43 | 显示全部楼层
Public Sub GetEndVch(strGroup As String, strMaker As String) '结转损益

    Dim iYear As Integer
    Dim iPeriod As Integer
    Dim strProfitandLossNum As String
    Dim strProfitandLossFullName As String
    Dim iMaxVchNum As Integer
    Dim iRowNum As Integer
    Dim dblAmount As Double
    Dim strCord As String
    Dim dteDate As Date
    Dim strAccType As String
    Dim strAccNum As String
    Dim strAccFullName As String
    Dim i As Integer
    Dim m As Integer
    Dim n As Integer
    Dim dblTotalAmount As Double
   
    strProfitandLossNum = Sheet15.Cells(9, 3)
   
    Dim lAccRow As Long
    Set r = Sheet12.Columns("B:B").Find(strProfitandLossNum, LookAt:=xlWhole)
    If Not r Is Nothing Then
        lAccRow = Sheet12.Columns("B:B").Find(strProfitandLossNum, LookAt:=xlWhole).Row
        strProfitandLossFullName = Sheet12.Cells(lAccRow, 3)
    Else
        lAccRow = 0
        MsgBox "本年利润科目没有设置或设置错误!"
        Exit Sub
    End If
   
    iCurrentYear = GetCurrentYear()
    iCurrentPeriod = GetCurrentPeriod()
    dteDate = GetMaxDate(iCurrentYear, iCurrentPeriod)
    iMaxVchNum = GetVchMaxNum
    m = 0
   
'判断损益类科目是否有余额
    Dim lAccRows As Long
    Dim lVchRows As Long
    Dim d
    lAccRows = Sheet12.Cells(Rows.Count, 2).End(xlUp).Row
    lVchRows = Sheet17.Cells(Rows.Count, 2).End(xlUp).Row
    Set d = CreateObject("Scripting.Dictionary")
    For l = 3 To lVchRows
        strAccNum = Sheet17.Cells(l, 9)
        iYear = CInt(Sheet17.Cells(l, 2))
        iPeriod = CInt(Sheet17.Cells(l, 3))
        If iPeriod = iCurrentPeriod And iYear = iCurrentYear Then
            Set r = Sheet12.Columns("B:B").Find(strAccNum, LookAt:=xlWhole)
            If Not r Is Nothing Then
                lAccRow = Sheet12.Columns("B:B").Find(strAccNum, LookAt:=xlWhole).Row
                strAccType = Sheet12.Cells(lAccRow, 5)
                strCord = Sheet12.Cells(lAccRow, 6)
                If strAccType = "损益" Then
                    If strCord = "借方" Then
                        dblAmount = Sheet17.Cells(l, 11)
                    Else
                        dblAmount = Sheet17.Cells(l, 12)
                    End If
                    d(strAccNum) = d(strAccNum) + dblAmount
                End If
             End If
        End If
    Next
    Set r = Nothing
    k = d.Keys
    t = d.items
    n = d.Count
    iRowNum = 1
    dblTotalAmount = 0
    If n = 0 Then
        MsgBox ("本期损益类科目发生额为零,无需结转")
        Exit Sub
    Else
        With Sheet17
            For i = 1 To n
                strAccNum = k(i - 1)
                dblAmount = t(i - 1)
                Set r = Sheet12.Columns("B:B").Find(strAccNum, LookAt:=xlWhole)
                If Not r Is Nothing Then
                    lAccRow = Sheet12.Columns("B:B").Find(strAccNum, LookAt:=xlWhole).Row
                    strAccFullName = Sheet12.Cells(lAccRow, 4)
                    strAccType = Sheet12.Cells(lAccRow, 5)
                    strCord = Sheet12.Cells(lAccRow, 6)
                    '写入记录
                    .Cells(lVchRows + 1, 2) = iCurrentYear
                    .Cells(lVchRows + 1, 3) = iCurrentPeriod
                    .Cells(lVchRows + 1, 4) = dteDate
                    .Cells(lVchRows + 1, 5) = strGroup
                    .Cells(lVchRows + 1, 6) = iMaxVchNum + 1
                    .Cells(lVchRows + 1, 7) = iRowNum
                    .Cells(lVchRows + 1, 8) = "结转损益"
                    .Cells(lVchRows + 1, 9) = strAccNum
                    .Cells(lVchRows + 1, 10) = strAccFullName
                    .Cells(lVchRows + 1, 11) = IIf(strCord = "借方", 0, dblAmount)
                    .Cells(lVchRows + 1, 12) = IIf(strCord = "贷方", 0, dblAmount)
                    .Cells(lVchRows + 1, 13) = 0
                    .Cells(lVchRows + 1, 14) = strMaker
                    .Cells(lVchRows + 1, 15) = ""
                    .Cells(lVchRows + 1, 16) = ""
                    .Cells(lVchRows + 1, 17) = 0
                    .Cells(lVchRows + 1, 18) = 0
                End If
                lVchRows = lVchRows + 1
                iRowNum = iRowNum + 1
                If strCord = "借方" Then
                    dblTotalAmount = dblTotalAmount - dblAmount
                Else
                    dblTotalAmount = dblTotalAmount + dblAmount
                End If
            Next
            
            If dblTotalAmount <> 0 Then
                .Cells(lVchRows + 1, 2) = iCurrentYear
                .Cells(lVchRows + 1, 3) = iCurrentPeriod
                .Cells(lVchRows + 1, 4) = dteDate
                .Cells(lVchRows + 1, 5) = strGroup
                .Cells(lVchRows + 1, 6) = iMaxVchNum + 1
                .Cells(lVchRows + 1, 7) = iRowNum
                .Cells(lVchRows + 1, 8) = "结转损益"
                .Cells(lVchRows + 1, 9) = strProfitandLossNum
                .Cells(lVchRows + 1, 10) = strProfitandLossFullName
                .Cells(lVchRows + 1, 11) = 0
                .Cells(lVchRows + 1, 12) = dblTotalAmount
                .Cells(lVchRows + 1, 13) = 0
                .Cells(lVchRows + 1, 14) = strMaker
                .Cells(lVchRows + 1, 15) = ""
                .Cells(lVchRows + 1, 16) = ""
                .Cells(lVchRows + 1, 17) = 0
                .Cells(lVchRows + 1, 18) = 0
               
                lVchRows = lVchRows + 1
                iRowNum = iRowNum + 1
            End If
        MsgBox ("结转损益成功,凭证号为:" & strGroup & iMaxVchNum + 1)
        End With
    End If

End Sub

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-18 16:49 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
乌鸦和矮人 发表于 2019-11-18 16:43
Public Sub GetEndVch(strGroup As String, strMaker As String) '结转损益

    Dim iYear As Integer

大师啊,这个没有具体的例子,看不清,参数定义这么多,我小白一枚,能给个从框架入手的一套东西吗。感觉问题复杂了很多,。

TA的精华主题

TA的得分主题

发表于 2019-11-18 16:53 来自手机 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
yzxfelix 发表于 2019-11-18 16:49
大师啊,这个没有具体的例子,看不清,参数定义这么多,我小白一枚,能给个从框架入手的一套东西吗。感觉 ...

表结法,不需要结转分录了

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-18 17:06 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2019-11-18 17:23 来自手机 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
yzxfelix 发表于 2019-11-18 17:06
您好,表结转法指什么呢?

总结一句话,账结法要产生凭证,表结法在任何时候都不产生凭证
https://baike.sogou.com/m/v54616830.htm?rcer=sXAvY9nI

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-25 05:42 | 显示全部楼层
乌鸦和矮人 发表于 2019-11-18 16:43
Public Sub GetEndVch(strGroup As String, strMaker As String) '结转损益

    Dim iYear As Integer

大师,这个够长啊,强人

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-12-19 20:35 | 显示全部楼层
乌鸦和矮人 发表于 2019-11-18 16:43
Public Sub GetEndVch(strGroup As String, strMaker As String) '结转损益

    Dim iYear As Integer

这代码真长啊

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-12-19 20:41 | 显示全部楼层
zpy2 发表于 2019-11-18 17:23
总结一句话,账结法要产生凭证,表结法在任何时候都不产生凭证
https://baike.sogou.com/m/v54616830.ht ...

哎,个人觉得的,会计学的概念,都是人为划分的,算不得科学。 前几十年这么说,算是划分概念为会计理论找个说法,而今,大数据,人工智能的推动,结转必须是到结到凭证分录。所谓表结法,应该算是历史堆里的。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-6-2 15:58 , Processed in 0.045463 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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