本文介绍了如何将公式输入作为条件格式化的UDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想想你想检查一个范围内每个单词的左侧字母是否为a,然后加入该条件为真的单词。一种方法是使用帮助列,如果不是真的返回,如果它以a开头,然后一行总计 和 FALSE 基于结果的值

  • 此数组可以传递给标准数组处理函数l ike CONCAT 或 SUM


    • 或者一个数组返回的UDF是不可能的,数组可以在内部传递给UDF的另一部分,然后处理它

    • 类似于 COUNTIF 必须在某点返回一个 TRUE的数组, / FALSE 在内部计数返回一个数字而不是一个数组,因此可以不作为数组公式输入。


  • 我对如何生成这个布尔阵列感兴趣



  • 现在研究显示有三种主要方式:数组函数,由于任何原因无法持有长字符串, CONCATIF / SUMIF 函数,它将文本参数作为布尔测试,但在测试类型中受到严格限制。第三种方法是条件格式化使用的方式;选择范围,公式测试运行在所选范围内的所有单元格,返回 TRUE 或 FALSE (内部),这个布尔数组用于格式化范围内的单元格。但是在UDF中,它们可以很容易地被传递,或者在内部被用于进一步的计算(例如,一个 CONCATIF 函数)



    因此,我正在寻找以下之一:(这不是一个数组公式的方法,应该理想地输入没有 + + 。)




    • 使用像$ COUNTIF 但更好:它接受一个范围参数和一个公式作为一个字符串,该公式是任何布尔返回的工作表公式,如 LEFT(cell)=a(注意,文本字符串)

    • 更好地使用UDF,使用条件格式化;接受一个范围和任何布尔返回公式*未格式化为文本


      • 这将是很好,因为您可以使用Excel自动提示和范围高创建公式,如果它是文本,则不能执行。


    • 对于选项1),布尔公式可以引用该词单元或其行为的范围对于选项2)它引用范围中的左上方单元格,如条件格式


      • 我'

    • $ b $(code code code code code code $ b
    • UDF可能会返回一些选项,可以进一步调整工作表函数或自定义计算,但正如我所说,我真的在布尔列表之后



    我最初没有输入,因为我不想为我提供一个代码但我想我已经提供了足够的细节再次(和独立思考的证明),现在是一个问题,如何不是不是什么,我相信在这方面更可以接受。


    pre> = TEXTJOIN(CHAR(32),TRUE,IF(LEFT(A1:INDEX(A:A,MATCH(zzz,A:A)))=a A1:INDEX(A:A,MATCH(zzz,A:A)),))





    ¹


    Imagine you want to check whether the left letter of each word in a range is "a", then join the words for which that condition is true. One way is with a helper column, returning "" if not true, the word if it begins with "a", and then a total row which CONCAT()s over the helper column.

    Another way would be to use an array formula. {=CONCAT(IF(LEFT(range) = "a", range, ""))}. That's effectively using a helper column anyway.

    But what I want is to use the conditional formatting approach: When applying conditional formatting, you reference the top left cell of your range. So for a range in A1:A10, I want a function like =CONCATIF(A1:A10, LEFT(A1) = "a").SUMIF and COUNTIF get close to this functionality, only they use string inputs ">", "=..." which cannot reference the cell which they are testing (i.e., there is no equivalent to LEFT(A1) since there is no way of referring to the_cell_I'm currently_working_on in the string)

    But the problem is, if I make a UDF which tries to accept a test like LEFT("A1") = "a", it just evaluates for that one cell, not over the whole range like Conditional formatting does.

    Why not just use an array formula?

    Well mainly I'm intrigued to see whether a vba function can act as an array formula in the way COUNTIF does - by evaluating some condition specified as a parameter. Only with the functionality of conditional formatting in accepting relative formulae, not string, inputs.

    But also, for this specific case, I'm trying to CONCAT some long paragraphs into a single string. Each paragraph is maybe 1000 characters, and for whatever reason, {=CONCAT(IF(LEFT(A1:A10) = "a", A1:A10, ""))} won't work since IF( returns a value error for the long paragraphs. The formula works for small paragraphs. But a VBA version can concat the whole of A1:A10, I just need a way to run the test condition first!

    Update


    To make it explicitly clear, I'm looking for the following:

    • A generic UDF which takes a RANGE as well as a Boolean FORMULA input
      • These can be in the same parameter of the UDF if required
    • The UDF evaluates the Boolean formula on each of the cells in the range
    • The UDF returns an array of TRUE and FALSE values based on the result
    • This array can be passed to standard array handling functions like CONCAT or SUM
      • Or if an array-returning UDF is not possible, the array can be passed internally to another portion of the UDF which then handles it
      • Similar to how COUNTIF must return an array of TRUE/FALSE at some point, but then counts them internally to return a number, not an array, and can therefore be entered not as an array formula.
    • I'm interested in how to generate this array of Booleans

    Now research shows there are 3 main ways: Array functions, which for whatever reason aren't able to hold long strings, CONCATIF/SUMIF type functions, which take a text parameter as the boolean test, but which are heavily limited in the types of test. The third approach is the one that Conditional formatting uses; a range is selected and the formula test runs over all of the cells in the selected range, returns TRUE or FALSE (internally), and this array of booleans is used to format the cells in the range. But in a UDF they could just as easily be passed as a result or used internally for further calculations (e.g. a CONCATIF function)

    Consequently, I'm looking for one of the following:(this is instead of an array formula approach, and should ideally be entered without ++.)

    • A UDF which uses an approach like COUNTIF but better: it accepts a range parameter and a formula as a string, the formula being any Boolean-returning worksheet formula such as 'LEFT(cell)="a" (note, a text string)
    • Better a UDF which uses an approach like conditional formatting; accepts a Range and any boolean-returning formula *not formatted as text"
      • That would be nice as you can use the Excel auto-prompt and range highliting to create the formula, which you couldn't do if it were text
    • For option 1), the boolean-formula can reference the word "cell" or the range over which it's acting. For option 2) it references the top-left cell in the range, like in conditional formatting
      • I'm thinking application.caller might be useful in extracting the formula part when it's not text.
    • The UDF could end up returning a number of options, could be tailored further with worksheet functions or with custom calculations, but as I say, I'm really after the list of booleans

    I didn't type that at first because I didn't want to make a code this for me question, but I think I've provided enough detail there (and proof of independant thought!) that it's now a matter of how not what, which I believe is more acceptable on SO.

    解决方案

    Use the newer TEXTJOIN¹ and IF in an array formula with CSE.

    =TEXTJOIN(CHAR(32), TRUE, IF(LEFT(A1:INDEX(A:A, MATCH("zzz", A:A)))="a", A1:INDEX(A:A, MATCH("zzz", A:A)), ""))
    

    ¹

    这篇关于如何将公式输入作为条件格式化的UDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-27 16:33