简体   繁体   中英

Building an Excel formula based on cell references

Is there any way I can build a formula based on user input including the logical functions? For example, a user could input

A1 must be <> 1

A1 would be in a cell (and I can use an indirect), with <> in an adjacent cell and the resulting formula would be =IF(A1<>1, TRUE, FALSE) , but the next time the user wants the formula to be

A1>1

so the cell would have A1 (again using an indirect for the resulting formula) and > in an adjacent cell to result in IF(A1>1,TRUE,FALSE)

一种方法是评估每种可能性(<>,> =,<=,=),然后使用匹配或查找功能根据用户输入选择正确的答案。

You can use Convert from Data menu, to split the contain of each cells using blank space as delimiter. You choose L column to write your formula (for example to avoid overlapping due to the split operation), and then you can assembly your criterions by concatenating the contents of the good cells to develop a formula.

you can check by CHER(60), CHAR(61) or CHAR(62) if cells contains respectively the symbol "<", "=" and ">".

hope this can help !

I take the following example, with 2 lines:

  1. A1 must be different from one <> 1
  2. A1 must be equal or greater than zero > 0

In cell B1, I'll have A1. In the next cell C1, I will have "must". In D1 "be", in E1 "different" and so on .. In H1 "<>" and I have "1" in I1. The second line goes therefore from cell B2 to K2, in J2 I have ">" and K2 to "0". I type 5 into cell A1 and 0 in cell A2. In cell M1, I type this line below to have my formula :

 =" = IF(" & "A1" & IF(LEN(C1)>2;"";IF(LEFT(C1;1)="<";C1;IF(LEFT(C1;1)="=";C1;IF(LEFT(C1;1)=">";C1;IF(ISNUMBER(C1);C1;"")))))&IF(LEN(D1)>2;"";IF(LEFT(D1;1)="<";D1;IF(LEFT(D1;1)="=";D1;IF(LEFT(D1;1)=">";D1;IF(ISNUMBER(D1);D1;"")))))&IF(LEN(E1)>2;"";IF(LEFT(E1;1)="<";E1;IF(LEFT(E1;1)="=";E1;IF(LEFT(E1;1)=">";E1;IF(ISNUMBER(E1);E1;"")))))&IF(LEN(F1)>2;"";IF(LEFT(F1;1)="<";F1;IF(LEFT(F1;1)="=";F1;IF(LEFT(F1;1)=">";F1;IF(ISNUMBER(F1);F1;"")))))&IF(LEN(G1)>2;"";IF(LEFT(G1;1)="<";G1;IF(LEFT(G1;1)="=";G1;IF(LEFT(G1;1)=">";G1;IF(ISNUMBER(G1);G1;"")))))&IF(LEN(H1)>2;"";IF(LEFT(H1;1)="<";H1;IF(LEFT(H1;1)="=";H1;IF(LEFT(H1;1)=">";H1;IF(ISNUMBER(H1);H1;"")))))&IF(LEN(I1)>2;"";IF(LEFT(I1;1)="<";I1;IF(LEFT(I1;1)="=";I1;IF(LEFT(I1;1)=">";I1;IF(ISNUMBER(I1);I1;""))))) & IF(LEN(J1)>2;"";IF(LEFT(J1;1)="<";J1;IF(LEFT(J1;1)="=";J1;IF(LEFT(J1;1)=">";J1;IF(ISNUMBER(J1);J1;""))))) & IF(LEN(K1)>2;"";IF(LEFT(K1;1)="<";K1;IF(LEFT(K1;1)="=";K1;IF(LEFT(K1;1)=">";K1;IF(ISNUMBER(K1);K1;""))))) & ";" & TRUE & ";" & FALSE & ")"

I apply my formula on M2 cells. After I copy my M1 and M2 cells, I paste By Value in N1. I replace blank space at the beginning of my formula in N1 et N2 by nothing and then the formula displays results. Let me know if you have problems with this formula because I developed it in Excel French. I will send you the complete file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM