Excel精英培训网

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

[已解决]自动分段计算收费

[复制链接]
发表于 2021-11-16 15:46 | 显示全部楼层 |阅读模式
分段收费计算.rar (10.53 KB, 下载次数: 27)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2021-11-16 16:17 | 显示全部楼层    本楼为最佳答案   
Sub demo()
   Price = [e11]
   If Price > [b10] Then [e11] = "超出计算范围": Exit Sub
   [f4:f10].ClearContents: a = [a4:f10]
   For i = 1 To UBound(a)
      If Price <= a(i, 1) Then Exit For
      a(i, 6) = (Price - a(i, 1) - Application.Max(0, Price - a(i, 2))) * a(i, 3)
   Next
   [a4].Resize(UBound(a), 6) = a
End Sub


祝順心,南無阿彌陀佛!


回复

使用道具 举报

 楼主| 发表于 2021-11-17 21:54 | 显示全部楼层
Private Sub CommandButton1_Click()
  Price = [e11]
  
   If Price > [b10] Then [e11] = "超出计算范围"
   Range("F3:F11").Select
    Selection.ClearContents
    [e11].Select: Exit Sub
   
    If Price <= [b3] Then [f3] = [c3]: Exit Sub
   
'    If Price <= [b10] Then
   [f4:f10].ClearContents: a = [a4:f10]
   For i = 1 To UBound(a)
      If Price <= a(i, 1) Then Exit For
      a(i, 6) = (Price - a(i, 1) - Application.Max(0, Price - a(i, 2))) * a(i, 3)
   Next
   [a4].Resize(UBound(a), 6) = a
   
   [f3] = 0.3
   Range("F11").Select
    Selection.FormulaR1C1 = "=SUM(R[-8]C:R[-1]C)"
'    End If
End Sub
改为上面的语句后,当预估金额<=b3时,运行语句则没有反应了。为什么?
回复

使用道具 举报

发表于 2021-11-17 22:49 | 显示全部楼层
心灵有约 发表于 2021-11-17 21:54
Private Sub CommandButton1_Click()
  Price = [e11]
  

拿掉紅色部份  If Price <= [b3] Then [f3] = [c3]: Exit Sub


回复

使用道具 举报

 楼主| 发表于 2021-11-19 22:00 | 显示全部楼层
cutecpu 发表于 2021-11-17 22:49
拿掉紅色部份  If Price

谢谢
回复

使用道具 举报

 楼主| 发表于 2021-12-16 18:09 | 显示全部楼层
cutecpu 发表于 2021-11-16 16:17
Sub demo()
   Price = [e11]
   If Price >  Then [e11] = "超出计算范围": Exit Sub

分段收费计算.rar (15.58 KB, 下载次数: 0)
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-9 08:18 , Processed in 0.113976 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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