我有一个公式来组合几个值:
M栏中的公式:
=IF(I15="Truck",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and ","And"),CHAR(32),"")),IF(I15="Bus",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")& "B1"),IF(I15="Car",CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")),"")& "C1"))
除了一小部分外,它起作用;只要C列中的值为空,默认情况下会将C1
填充到列M中。 M列中的值应为空白。
有什么想法吗?
答案 0 :(得分:1)
真正的问题是I15
为空时。使用“评估公式”工具运行,您应该看到它,但如果您破坏了代码并使用缩进/换行等格式化它:
=IF(I15="Truck",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and ","And"), 'Should this be "and" rather than "and " to match the "Bus" and "Car"?
CHAR(32),
""
)
),
IF(I15="Bus",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)& "B1"
),
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
), 'Should this bracket be after the "C1" instead of here?
""
)& "C1"
)
)
现在,如果I15
为空,请追踪:I15
不是“卡车”而I15
不是“公交”,所以我们得到:
=IF(FALSE,
N/A,
IF(FALSE,
N/A,
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
), 'Should this bracket be after the "C1" instead of here?
""
)& "C1"
)
)
简化下来,你得到:
IF(I15="Car",
CLEAN(
SUBSTITUTE(
SUBSTITUTE(TRIM(C15),"and","And"),
CHAR(32),
""
)
),
""
)& "C1"
但是,I15
是空白的,而不是“Car”,所以它变为IF(FALSE, N/A, "") & "C1"
- 意思是,如果I15
不是“公共汽车”或“卡车”,它将始终说“C1” ”
此外,您可以将代码简化为=CLEAN(SUBSTITUTE(SUBSTITUTE(TRIM(C15),"and","And"),CHAR(32),"")) & IF(I15="Bus", "B1", IF(I15="Car", "C1", ""))
如果您可以在某处设置表格,则可以将IF
语句更改为VLOOKUP
,或者如果您有下拉值表,则可以使用CHOOSE(MATCH(..))