Excel精英培训网

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

整合计算公式

[复制链接]
发表于 2019-1-4 14:59 | 显示全部楼层 |阅读模式
跪求各位老师指点

Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 1 And Target.Column > 4 And Target.Column < 12 Then
i = Target.Row
Cells(i, 9) = Cells(i, 8) / Cells(i, 7)           这个和下面这个如何整合在一起啊!
Cells(i, 12) = Cells(i, 11) / Cells(i, 10)     这个存在以后输入前面的时候就溢出了!
End If
End Sub


工作簿2.zip (12.18 KB, 下载次数: 4)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2019-1-5 17:44 | 显示全部楼层
Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

If Target.Row > 1 And Target.Column > 4 And Target.Column < 12 Then
i = Target.Row
Cells(i, 9) = Cells(i, 8) / Cells(i, 7)           这个和下面这个如何整合在一起啊!
Cells(i, 12) = Cells(i, 11) / Cells(i, 10)     这个存在以后输入前面的时候就溢出了!
End If
End Sub
加一句就行了
回复

使用道具 举报

 楼主| 发表于 2019-1-8 14:39 | 显示全部楼层
sjcym 发表于 2019-1-5 17:44
Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("C2:C65536")) Is Nothing Or Target.Count > 1 Then Exit Sub
Dim i&, st As Worksheet, Arr, d, n&
n = Target.Row
Set st = Sheets("数据data")
Set d = CreateObject("Scripting.Dictionary")
Arr = st.[b1].CurrentRegion
For i = 3 To UBound(Arr)
    d(Arr(i, 1)) = i
Next
If d.exists(Target.Value) Then
    i = d(Target.Value)
    Target.Offset(0, -1).Value = Date                        '写入销售日期/写入编码
    Target.Offset(0, 1) = Arr(i, 2)   '写入入库名称
    Target.Offset(0, 2) = Arr(i, 3)   '写入规格型号
    Target.Offset(0, 3) = Arr(i, 4)   '写入类别
    Target.Offset(0, -2) = "IQC1900" & Format(n - 1, "000")
    Cells(n, 9).Formula = "=if(rc[-2]="""","""",rc[-1]/rc[-2])"
    Cells(n, 12).Formula = "=if(rc[-4]="""","""",1-(rc[-1]+rc[-2])/rc[-4])"
End If
End Sub


老师,能否和这段代码融合在一起;或者是让红色这两段出来的值变为文本值(现在填入单元格的是公式)

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-24 09:16 , Processed in 0.285158 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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