Excel精英培训网

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

[已解决]返利目标

[复制链接]
发表于 2011-11-10 10:43 | 显示全部楼层 |阅读模式
各位前辈,大家好!小妹遇到一个难道,希望得到大家帮助!
问题是这样的,最近在统计客户返利,表格如下 QQ截图未命名.jpg 返利目标.rar (7.61 KB, 下载次数: 8)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2011-11-10 10:56 | 显示全部楼层
示例少了一些,请多提供写数据示例。
回复

使用道具 举报

发表于 2011-11-10 11:24 | 显示全部楼层
  1. Function Mb(Rn As Range, RnX As Range, Optional k As Boolean = False) As Variant
  2.     Application.Volatile
  3.     Dim m, i As Byte, t As Long
  4.     With CreateObject("vbscript.regexp")
  5.         .Global = True
  6.         .Pattern = "(^|,)(\d+)"
  7.         If .test(Rn.Value) Then
  8.             For Each m In .Execute(Rn.Value)
  9.                 i = i + 1: t = CLng(m.submatches(1))
  10.                 If t >= RnX.Value * 0.0001 Then
  11.                     If k Then
  12.                         Mb = Format(RnX.Value / t / 10000, "0.00%")
  13.                     Else
  14.                         Mb = "目标" & i
  15.                     End If
  16.                     Exit For
  17.                 End If
  18.             Next
  19.         End If
  20.     End With
  21. End Function
复制代码
返利目标.rar (13.24 KB, 下载次数: 3)
回复

使用道具 举报

 楼主| 发表于 2011-11-10 12:31 | 显示全部楼层
本帖最后由 nancy66317 于 2011-11-10 12:33 编辑

感觉有点不稳定,修改了数据,就变成0了,想请问一下代码的含义

回复

使用道具 举报

 楼主| 发表于 2011-11-10 12:39 | 显示全部楼层
liuguansky 发表于 2011-11-10 11:24
试下这个自定义函数
D2
e2

你好,请问一下这段代码是什么意思呢?
With CreateObject("vbscript.regexp")
        .Global = True
        .Pattern = "(^|,)(\d+)"
        If .test(Rn.Value) Then
            For Each m In .Execute(Rn.Value)
                i = i + 1: t = CLng(m.submatches(1))
                If t >= RnX.Value * 0.0001 Then
回复

使用道具 举报

 楼主| 发表于 2011-11-10 12:43 | 显示全部楼层
liuguansky 发表于 2011-11-10 11:24
试下这个自定义函数
D2
e2

这是一个加了数据的表 返利目标(1).rar (13.67 KB, 下载次数: 12)
回复

使用道具 举报

发表于 2011-11-10 17:13 | 显示全部楼层    本楼为最佳答案   
本帖最后由 liuguansky 于 2011-11-10 17:14 编辑
nancy66317 发表于 2011-11-10 12:43
这是一个加了数据的表


依沟通后结果及附件:
  1. Function Mb(Rn As Range, RnX As Range, Optional k As Boolean = False) As Variant
  2.     Application.Volatile
  3.     Dim m, i As Byte, t As Long, s$
  4.     With CreateObject("vbscript.regexp")
  5.         .Global = True
  6.         .Pattern = "(^|[,;])(\d+)"
  7.         s = Mid(Rn.Value, 6)
  8.         If .test(s) Then
  9.             For Each m In .Execute(s)
  10.                 i = i + 1: t = CLng(m.submatches(1))
  11.                 If t >= RnX.Value * 0.0001 Then
  12. 100
  13.                     If k Then
  14.                         Mb = Format(RnX.Value / t / 10000, "0.00%")
  15.                     Else
  16.                         Mb = "目标" & i
  17.                     End If
  18.                     Exit Function
  19.                 End If
  20.             Next
  21.             If Len(Mb) = 0 Then GoTo 100
  22.         End If
  23.     End With
  24. End Function
复制代码

表格公式同上。
返利目标(3).rar (9.51 KB, 下载次数: 28)
回复

使用道具 举报

 楼主| 发表于 2011-11-10 17:18 | 显示全部楼层
谢谢,liuguansky 太热心了!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-15 15:07 , Processed in 0.316046 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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