• excel VBA 编程



    Dim cuttent_columns As Integer Dim care_repeat As Integer Private Sub Workbook_Open() Dim i As Integer Dim j As Integer '确定cuttent_columns的值 For i = 1 To 100 If Cells(1, i) = "" Then For j = i To 100 If Cells(1, j) = "" Then Else cuttent_columns = j - 1 'MsgBox "init cuttent_columns" 'MsgBox cuttent_columns Exit Sub End If Next End If Next End Sub Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) On Error Resume Next '跳过异常 Application.ScreenUpdating = False '关闭屏幕更新 If care_repeat = 1 Then care_repeat = 0 'MsgBox "防止正反馈" Exit Sub End If If Target.Row > 51 Then Exit Sub 'MsgBox "cuttent_columns" 'MsgBox cuttent_columns 'MsgBox "Target.Row" 'MsgBox Target.Row 'MsgBox "Target.Target.Column" 'MsgBox Target.Column Dim null_flag As Integer Dim i As Integer null_flag = 0 If Cells(Target.Row, 2) = 0 Or Cells(Target.Row, 2) = "" Then Else For i = 2 To cuttent_columns If Cells(Target.Row, i) = "" Then care_repeat = 1 Cells(Target.Row, i) = Cells(Target.Row, 2) care_repeat = 1 Cells(Target.Row, 2) = 0 null_flag = 1 Exit For End If Next If null_flag = 0 Then cuttent_columns = cuttent_columns + 1 care_repeat = 1 ActiveSheet.Columns(cuttent_columns).Insert care_repeat = 1 Cells(Target.Row, cuttent_columns) = Cells(Target.Row, 2) care_repeat = 1 Cells(Target.Row, 2) = 0 End If End If '计算总和 Dim littel_total As Integer Dim littel_total_num As Integer Dim big_total_num As Integer littel_total = cuttent_columns + 1 littel_total_num = 0 big_total_num = 0 '计算小总和 For i = 3 To cuttent_columns littel_total_num = littel_total_num + Cells(Target.Row, i) Next care_repeat = 1 Cells(Target.Row, littel_total) = littel_total_num '判断 If Cells(Target.Row, littel_total) > Cells(53, 2) Then care_repeat = 1 Cells(Target.Row, littel_total + 1) = "金额超过阈值" Else care_repeat = 1 Cells(Target.Row, littel_total + 1) = "" End If '计算大总和 For i = 2 To 51 big_total_num = big_total_num + Cells(i, littel_total) Next care_repeat = 1 Cells(52, littel_total) = big_total_num Application.ScreenUpdating = True '恢复屏幕更新 End Sub

      

  • 相关阅读:
    MYSQL删除表的记录后如何使ID从1开始
    Python chardet 字符编码判断
    中文搜索引擎技术揭密
    python 处理中文网页时,忽略特殊字符,忽略异常
    cmd 之基础命令
    自己写的删除主键的存储过程
    朝花夕拾delphi的三层结构
    ERWIN中的一对多标识关系和一对多非标识关系
    翻页用的SQL
    关于 Ajax 的一篇通俗易懂的文章
  • 原文地址:https://www.cnblogs.com/mingyunrangwozoudaoxianzai/p/11604175.html
Copyright © 2020-2023  润新知