Excel精英培训网

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

为什么同样代码一张表能算一张不能算真晕

[复制链接]
发表于 2020-11-24 10:03 | 显示全部楼层 |阅读模式
本帖最后由 flytoday02 于 2020-11-24 10:06 编辑

麻烦各位大师能改改是不是哪错了,谢谢,工作表复制一张后也变成用不了——,

1.zip

33.62 KB, 下载次数: 4

 楼主| 发表于 2020-11-24 10:13 | 显示全部楼层
Function test(str)
str = Replace(Replace(Replace(Replace(str, "{", "("), "}", ")"), "(", "("), ")", ")")
str = Replace(Replace(str, "×", "*"), "÷", "/") '"×") '÷
With CreateObject("vbscript.regexp")
   .Global = True
    .Pattern = "\[.+?\]"
   test = Application.Evaluate(.Replace(str, ""))
End With
End Function
回复

使用道具 举报

 楼主| 发表于 2020-11-24 10:14 | 显示全部楼层
Function test(str)
str = Replace(Replace(Replace(Replace(str, "{", "("), "}", ")"), "(", "("), ")", ")")
str = Replace(Replace(str, "×", "*"), "÷", "/") '"×") '÷
With CreateObject("vbscript.regexp")
   .Global = True
    .Pattern = "\[.+?\]"
   test = Application.Evaluate(.Replace(str, ""))
End With
End Function
回复

使用道具 举报

 楼主| 发表于 2020-11-24 10:14 | 显示全部楼层
这以前都用的好好的现在用不了了
回复

使用道具 举报

发表于 2020-11-24 12:14 | 显示全部楼层
看上去 都可以 , 是不是 宏没启用?
回复

使用道具 举报

 楼主| 发表于 2020-11-24 12:48 | 显示全部楼层
有启用啊~~~
回复

使用道具 举报

发表于 2020-11-24 13:02 | 显示全部楼层
我这里 1.xls 与 2.xls 都有结果

================
Ps:

减了 2 个 replace函数
Function tt(str)

    With CreateObject("vbscript.regexp")
       .Global = True
        .Pattern = "(\[.+?\])|(\ )"
       str = .Replace(str, "")
    End With
   
    str = Replace(Replace(str, "{", "("), "}", ")")
    str = Replace(Replace(str, "×", "*"), "÷", "/") '"×") '÷
   
    tt = Application.Evaluate(str)
   
End Function
------------------------------------------------
这样不用replace函数
Function tt(str)

    Dim i, p1, p2
    p1 = Array("(\[.+?\])|(\ )", "{", "}", "×", "÷")
    p2 = Array("", "(", ")", "*", "/")
   
    With CreateObject("vbscript.regexp")
       .Global = True
      
       For i = 0 To UBound(p1)
        .Pattern = p1(i)
       str = .Replace(str, p2(i))
       Next i
    End With
   
    tt = Application.Evaluate(str)
   
End Function
回复

使用道具 举报

 楼主| 发表于 2020-11-24 15:03 | 显示全部楼层
楼上大师你这个也用不了啊
回复

使用道具 举报

 楼主| 发表于 2020-11-26 10:14 | 显示全部楼层
哪位哥麻烦解决下,原来这样的代码计算表全不能用了,麻烦解决下谢谢
回复

使用道具 举报

 楼主| 发表于 2020-11-26 16:42 | 显示全部楼层
原来代码,重新做一次可以——第二次打开后又不行了——,
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-18 09:23 , Processed in 0.480643 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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