ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 麻烦哪位大师用VBA帮我改进一下

[复制链接]

TA的精华主题

TA的得分主题

发表于 2020-3-28 18:07 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
麻烦哪位大师用VBA,帮我写一下,谢谢!!!就是借方减贷方余额,不停地往下计算并将结果显示在对应L列,没数据就停止计算
71100437c67debb3.png

TA的精华主题

TA的得分主题

发表于 2020-3-28 23:38 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
用公式可以处理,一定要用VBA?

TA的精华主题

TA的得分主题

发表于 2020-3-28 23:40 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
用公式可以处理,一定要用VBA?
改进,现在的余额是VBA算出来的?

TA的精华主题

TA的得分主题

发表于 2020-3-29 09:24 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-3-30 11:26 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-3-30 11:27 | 显示全部楼层
dgerwin 发表于 2020-3-28 23:40
用公式可以处理,一定要用VBA?
改进,现在的余额是VBA算出来的?

现在就是用公式处理的!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-3-30 11:28 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
zxmg2009 发表于 2020-3-29 09:24
你这个要标明余额的借贷方向,否则看不懂余额

负数就是贷方余额了!!

TA的精华主题

TA的得分主题

发表于 2020-3-30 12:09 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
现在複製粘贴自已以前编的一大堆垃圾到下面,
其中有一行代码是计算余额的。这个代码的用途:根据输入的会计科目代码,根据年初余额及凭证,生成明细账。

If Target.Row = 2 And Target.Column = 7 Then
   

pzend = Sheet3.Range("E2").End(xlDown).Row
subNo = Trim(CStr(Sheet8.Range("g2").Value))
On Error Resume Next
kmin = Application.WorksheetFunction.VLookup(subNo, Sheet2.Range("A2:F" & Sheet9.Range("E4").Value), 6, 0)

arr1 = Sheet3.Range("b3:J" & pzend).Value
j = 0

pginl = Sheet8.Range("g1").Value

pgn = Int(j / pginl) + 1
Sheet8.Select
'Sheet8.Range("A9:I15000").ClearContents
Sheet8.Range("A9:I15000").Clear
Sheet8.Range("A9:I15000").Font.Size = 12
'Sheet8.Range("a9:i15000").PageBreak = xlPageBreakNone

Sheet8.Range(Cells(8, 2), Cells(9 + pginl, 8)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With





With Sheet8
       If (j Mod pginl) = 0 Then
        .Cells(j + pgn * 8, 2).Value = "  月 "
         .Cells(j + pgn * 8, 2).Value = "  月 "
         .Cells(j + pgn * 8, 2).Value = "  月 "
       .Cells(j + pgn * 8, 2).Value = "  月 "
       .Cells(j + pgn * 8, 3).Value = " 凭证号"
       .Cells(j + pgn * 8, 4).Value = "  摘要 "
       .Cells(j + pgn * 8, 5).Value = "借方金额 "
       .Cells(j + pgn * 8, 6).Value = "  贷方金额 "
       .Cells(j + pgn * 8, 7).Value = "  余额  "
       .Cells(j + pgn * 8, 8).Value = "核对"
      
       End If
End With
If kmin <> 0 Then
   
    Sheet8.Range("D9").Value = "上年结转"
    Sheet8.Range("G9").Value = kmin
    kmye = kmin
    j = 2
    Else
    j = 1
    kmye = 0
    End If

For i = 1 To pzend - 2
    If arr1(i, 4) = subNo Then
   
       With Sheet8
      
            
       .Cells(j + pgn * 8, 2).Value = arr1(i, 1)
       .Cells(j + pgn * 8, 3).Value = arr1(i, 2)
       .Cells(j + pgn * 8, 4).Value = arr1(i, 3)
       .Cells(j + pgn * 8, 5).Value = arr1(i, 8)
       .Cells(j + pgn * 8, 6).Value = arr1(i, 9)
         kmye = kmye + arr1(i, 8) - arr1(i, 9)    '计算余额
       .Cells(j + pgn * 8, 7).Value = kmye
        
      
       If (j Mod pginl) = 0 Then
        .Cells(j + pgn * 8 + 1, 4).Value = " 转 下 页 "
         End If
         j = j + 1
          pgn = Int((j - 1) / pginl) + 1
         
         
         If ((j - 1) Mod pginl) = 0 Then
         '.HPageBreaks.Creator
       '  .HPageBreaks.Add (.Cells(j + pgn * 8 - 6, 4))
         .Cells(j + pgn * 8 - 4, 4).Value = .Cells(6, 4).Value
         .Cells(j + pgn * 8 - 4, 4).Font.Size = 16
           .Cells(j + pgn * 8 - 3, 2).Value = .Cells(7, 2).Value
       .Cells(j + pgn * 8 - 3, 4).Value = .Cells(7, 4).Value
       .Cells(j + pgn * 8 - 4, 7).Value = .Cells(6, 7).Value
       .Cells(j + pgn * 8 - 3, 7).Value = "页数:第" & pgn & "页"
            
         
       .Cells(j + pgn * 8 - 2, 2).Value = "  月 "
       .Cells(j + pgn * 8 - 2, 3).Value = " 凭证号"
       .Cells(j + pgn * 8 - 2, 4).Value = "  摘要 "
       .Cells(j + pgn * 8 - 2, 5).Value = "借方金额 "
       .Cells(j + pgn * 8 - 2, 6).Value = "  贷方金额 "
       .Cells(j + pgn * 8 - 2, 7).Value = "  余额  "
       .Cells(j + pgn * 8 - 2, 8).Value = "核对"
        .Cells(j + pgn * 8 - 1, 4).Value = " 承上页 "
        .Cells(j + pgn * 8 - 1, 7).Value = kmye
        
        .Range(Cells(j + pgn * 8 - 2, 2), Cells(j + pgn * 8 + pginl, 8)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
      
               
        End If
      
         
      
      
    End With
    End If


Next i


With Sheet8

     .Range("c7:c1500").NumberFormatLocal = "##"
     .Range("E9:F" & .Range("G65535").End(xlUp).Row).NumberFormatLocal = "#,##0.00"
      .Range("G9:G" & .Range("G65535").End(xlUp).Row).NumberFormatLocal = """借  ""#,##0.00;""贷  ""##,##0.00;""平"""
End With

Sheet8.Range("f6").Select
End If

End Sub
头像被屏蔽

TA的精华主题

TA的得分主题

发表于 2020-3-30 21:49 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

TA的精华主题

TA的得分主题

发表于 2020-3-30 22:24 | 显示全部楼层
都说过是一大堆垃圾,只有其中几行可以参照,不可以照搬来用。

你查看一下新手必读,
在文件中提出要求,解释什么情况下计余额什么情况下不计余额,然后压缩上传.

用一行公式,还是用一大堆代码,我宁愿选择前者。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-10-1 15:27 , Processed in 0.045671 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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