简体   繁体   English

Excel-文字或数字公式

[英]Excel - Text Or Number Formula

I'm wondering if there's a shortcut to the following. 我想知道下面是否有捷径。

I have a product form that customers will fill out and I need the formula to format the part numbers they enter correctly. 我有一个客户可以填写的产品表格,我需要公式来格式化他们正确输入的零件号。 If it doesn't their entry doesn't match the products list. 如果不是,则其条目与产品列表不匹配。

Below are the variety of text/number/other variations... Excel Columns/ Rows Example 以下是各种文本/数字/其他变体... Excel列/行示例

    101
7-2009
7-5601-RT
G-2121
5728B
PI-PIXES

I got all but the last one working with this formula: FORMULA1 除了最后一个公式,我得到了所有公式: FORMULA1

=AND(SUMPRODUCT(--ISNUMBER(--MID(B40,ROW($1:$9996),1)))<LEN(B40),MIN(FIND({0,1,2,3,4,5,6,7,8,9},B40&"0123456789"))<=LEN(B40))

I also have to keep it in .xls format. 我还必须将其保持为.xls格式。 Basically, I have one column that checks this above and it returns TRUE/FALSE. 基本上,我有一列在上面进行检查,它返回TRUE / FALSE。

I have another formula that checks for text: FORMULA2: 我还有另一个检查文本的公式: FORMULA2:

=IF(I40=FALSE,"NUMBER", "TEXT")

The final column TESTS FOR TEXT/NUMBER. 最后一栏TESTS FOR TEXT / NUMBER。 FORMULA3: FORMULA3:

=IF(J40 = "NUMBER", VALUE(B40), B40)

PI-PIXES is flagged as number because of the dash(hyphen). 由于连字符(-),PI-PIXES被标记为数字。

Without any other option, I'm considering adding a third column to find TEXT with hyphens. 如果没有其他选择,我正在考虑添加第三列以查找带连字符的TEXT。 I would then change FORMULA3 check if both if column 1 = TRUE+column 2 = TRUE and column 3 = TEXT but this is getting complicated and I'm wondering if there's a shortcut. 然后,我将更改FORMULA3,以检查列1 = TRUE +列2 = TRUE和列3 = TEXT是否都同时出现,但这变得越来越复杂,我想知道是否存在捷径。

I think this does it: 我认为这样做:

=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"@"),B40,IFERROR(VALUE(B40),B40))

If there are hyphens, it returns the B40 unchanged, eliminating dates. 如果有连字符,它将返回B40不变,并消除日期。 Otherwise, it handles it as a normal Value conversion with IFERROR. 否则,它将使用IFERROR将其作为普通的值转换进行处理。

This should work for older versions of Excel: 这应该适用于旧版本的Excel:

=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"@"),B40,IF(ISERR(VALUE(B40)),B40,VALUE(B40)))

Or even this: 甚至这个:

=IF(ISERR(FIND("-",B40)),IF(ISERR(VALUE(B40)),B40,VALUE(B40)),B40)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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