将长字符串(> 255个字符)评估为数组

发布于 2025-01-22 07:15:52 字数 690 浏览 0 评论 0 原文

因此,我经常发现自己在Excel上执行任务,涉及将文本字符串作为数组进行评估。一般来说,我只是使用它:

Function EVAL(Ref As String)
    EVAL = Evaluate(Ref)
End Function

例如:例如:

=EVAL("{"&CHAR(34)&SUBSTITUTE(TEXTJOIN(";",TRUE,MID(Index[Industries],2,LEN(Index[Industries])-2)),";",CHAR(34)&";"&CHAR(34))&CHAR(34)&"}")

此示例中的单元格将具有以下内容:(

;Automotive;Rail;Energy;
;Automotive;Rail;
;Energy;
;Automotive;Aerospace;

碰巧的是,这是我现在遇到的确切问题过去的方式。)

过去这对我有用,但是最近我遇到了困难。

我得出的结论是不起作用的,因为application.evaluate,事实证明,字符限制为255。 - 当我使用它将文本字符串解释为数组而不是公式时,他们似乎不起作用的人似乎不起作用。

是否有一些技巧可以使它起作用? (或者,实际上,是否有一些完全实现这一目标的替代方法?)

So I quite often find myself doing tasks on Excel which involve evaluating a text string as an array. Generally speaking I just use this:

Function EVAL(Ref As String)
    EVAL = Evaluate(Ref)
End Function

So the formula will be, for example:

=EVAL("{"&CHAR(34)&SUBSTITUTE(TEXTJOIN(";",TRUE,MID(Index[Industries],2,LEN(Index[Industries])-2)),";",CHAR(34)&";"&CHAR(34))&CHAR(34)&"}")

The cells in this example will have contents like:

;Automotive;Rail;Energy;
;Automotive;Rail;
;Energy;
;Automotive;Aerospace;

(As it happens this is the precise problem I'm stuck on right now, though it has come up in different ways in the past.)

This has worked for me in the past, but I've been running into difficulties lately.

I have come to the conclusion it isn't working because application.evaluate, it turns out, has a character limit of 255. I've seen examples of VBA tricks to bypass this for text strings that are formulas rather than arrays, but copy-pasting those they don't seem to work for when I'm using it to interpret a text string as an array rather than as a formula.

Is there some trick to get this to work? (Or, indeed, is there some alternative method to achieve this altogether?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃→可爱长大的 2025-01-29 07:15:52

是的,根据我的评论,如果您使用的是MS365,则可以避免使用工作簿为XLSM,只是因为您需要将值拆分为数组。利用本机函数可用的内容,例如:

”在此处输入图像说明“

公式在 c2 中:

=TEXTSPLIT(CONCAT(A1:A4),,";",1)

d2 中的公式:

=FILTERXML("<t><s>"&SUBSTITUTE(CONCAT(A1:A4),";","</s><s>")&"</s></t>","//s[node()]")

注释1:< /strong>根据写作时间,您需要启用beta-channel才能访问 textsplit() ,如果我没记错的话,允许您的版本(2203)开始使用此功能。只需 google 如何获取访问并更新excel。

显然,这两种选项都可以嵌套在 unique() 功能。


注2:如果在任何时候 concat() 达到了限制(32767个字符,谢谢@scottcraner),也许您可​​以避免在Lambda的Helper helper函数的帮助下避免使用它=“ https://support.microsoft.com/en-us/office/reduce-function-42E39910-B345-45F3-84B8-0642B568B7CB” /a>:

=TEXTSPLIT(REDUCE("",A1:A4,LAMBDA(a,b,a&b)),,";",1)

注释3 :如果您还不能更新excel,并且您想知道如何使用 filts> filterxml() 写一会儿在这里

Right, as per my comments, if you are using ms365, you could avoid your workbook to be xlsm just because you need to split values into an array. Make use of what is available with native functions, for example:

enter image description here

Formula in C2:

=TEXTSPLIT(CONCAT(A1:A4),,";",1)

Formula in D2:

=FILTERXML("<t><s>"&SUBSTITUTE(CONCAT(A1:A4),";","</s><s>")&"</s></t>","//s[node()]")

Note 1: As per time of writing you'd need to enable the BETA-channel to gain access to TEXTSPLIT(), and if I recall correctly your version (2203) is allowed to start using this function. Just google how to get access and update your Excel.

Both options can obviously be nested inside the UNIQUE() function.


Note 2: If at any point CONCAT()'s limits are reached (32767 characters, thanks @ScottCraner), maybe you can avoid using that with help of the lambda's helper function REDUCE():

=TEXTSPLIT(REDUCE("",A1:A4,LAMBDA(a,b,a&b)),,";",1)

Note 3: In case you can't update your Excel just yet, and you wonder how to use FILTERXML(), don't mind me refering you to another post I wrote a while back here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文