Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2095|回复: 5

[已解决]请老师修改一下代码

[复制链接]
发表于 2014-2-17 12:48 | 显示全部楼层 |阅读模式
排序.rar (8.24 KB, 下载次数: 14)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-2-17 13:58 | 显示全部楼层
修改代码来解决什么问题,比明白。
回复

使用道具 举报

 楼主| 发表于 2014-2-17 14:27 | 显示全部楼层
过江龙 发表于 2014-2-17 13:58
修改代码来解决什么问题,比明白。

运行后 最后1列不能生成数据
主要是排序后,结存数不对
回复

使用道具 举报

发表于 2014-2-18 09:34 | 显示全部楼层    本楼为最佳答案   
qh8600 发表于 2014-2-17 14:27
运行后 最后1列不能生成数据
主要是排序后,结存数不对

Private Sub CommandButton1_Click()
  Dim arr, brr, crr
  Dim i As Integer, j As Integer, n As Integer
  Application.ScreenUpdating = False
   With Sheets("记录")
     .Range(.Cells(4, 1), .Cells(.[a65536].End(xlUp).Row, 8)).Sort Range("A4"), xlAscending, Header:=xlNo
      arr = .Range(.Cells(1, 1), .Cells(.[a65536].End(xlUp).Row, 8))
    End With
    ReDim brr(1 To UBound(arr), 1 To 8)
    For i = 4 To UBound(arr)
    If arr(i, 1) <> 0 Then
            n = n + 1
            For j = 1 To 7
              brr(n, j) = arr(i, j)
            Next j
            If n = 1 Then
               brr(n, 8) = Cells(3, 8) + brr(n, 5) - brr(n, 7)
              Else
               brr(n, 8) = brr(n - 1, 8) + brr(n, 5) - brr(n, 7)
             End If
    End If
    Next i
    With Sheets("记录")
           .Rows("4:" & .[a65536].End(xlUp).Row).Delete Shift:=xlUp
           .Range("A4").Resize(UBound(brr), 8) = brr
           .Range("A1").Resize(UBound(brr), 8).Borders.LineStyle = 1
    End With
Application.ScreenUpdating = True
End Sub

回复

使用道具 举报

发表于 2014-2-20 10:36 | 显示全部楼层
学习了
回复

使用道具 举报

发表于 2014-2-20 10:37 | 显示全部楼层
学习了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-22 09:42 , Processed in 0.207949 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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