excel VBA 编程
2024-09-07 22:53:29
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
最新文章
- WCF分布式开发必备知识(1):MSMQ消息队列
- python 中类方法@classmethod
- 初学java之StringBuffer类的常用方法
- 极客DIY:如何构建一台属于自己的基站
- activiti自定义流程之整合(四):整合自定义表单部署流程定义
- MySQL优化技巧之四(数据库设计中的一些技巧)
- MySQL定期分析检查与优化表
- Zend Studio的配置和使用
- line-height属性详解
- C#之Action和Func的用法
- 【工具】Idea GenerateAllSetter
- 自制操作系统Antz(14)——实现内置编程语言(词法解析器)
- iOS AppIcon尺寸
- 读书笔记--SQL必知必会--常用MySQL(MariaDB)命令及示例
- bat输出重定向
- k8s-rabbitmq-(一)集群部署
- <;魔鬼投资学>;读书笔记
- # WinForm关闭窗体确认
- PostMan 使用Interceptor 发送带cookie的请求一直loading
- python OSError: [Errno 22] Invalid argument: &#39;D:\\crawle\x01.html1&#39;
热门文章
- jQuery入门教程-文档操作方法
- html from表单异步处理
- xsxsxsxsxsxsxsxs
- eureka注册中心wro.css wro.js 404
- linux 统计代码行数
- mysql_DCL_grant/revoke
- mybatis有结果返回null
- SQL的一对多,多对一,一对一,多对多
- spring事务——try{...}catch{...}中事务不回滚的几种处理方式(转载)
- vue构造器注册UI组件