Excel:数据验证,如何强制用户输入一个2 char长的字符串? [英] Excel : Data Validation, how to force the user to enter a string that is 2 char long?

查看:374
本文介绍了Excel:数据验证,如何强制用户输入一个2 char长的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在最新的Excel中的单元格中添加一些数据验证。我想强制用户输入两个字符长的字符串,第一个字符是数字,第二个字符是一个字母。



eg

  1m 
2m
9w
8y
/ pre>

你会怎么做?



此外,如果输入小写字母, d />

解决方案

只适用于第一部分(不需要VBA) ,您可以使用数据验证:




  • 选择要检查的单元格( A1 例如)

  • 在功能区中,转到数据>数据验证

  • 允许:,选择自定义

  • 在该字段中,输入以下公式: = IF(AND( LEN(A1)= 2,ISNUMBER(VALUE(LEFT(A1,1))),ISTEXT(RIGHT(A1,1))),TRUE,FALSE)

  • 在选项卡错误警报中,更改对话框向用户说明什么他应该这样做:




您必须输入一个数字,后面加上一封信。 p>

Btw,您可以使用 UPPERCASE test添加支票。



还可以看一下类似但优化的解决方案的brettj的答案


I would like to add some data validation on a cell in the latest Excel. I would like to force the user to enter a string that is two-char long, with the first char a digit, and the second char a letter.

e.g.

1m
2m
9w
8y

How would you do that?

Also, if a lower case letter is entered, i'd like to render it an upper case letter when the input is finished.

解决方案

Only for the first part (no VBA needed), you can use Data Validation:

  • Select the cell you want to check (A1 for instance)
  • In the Ribbon, go to Data > Data Validation
  • In the Allow:, choose Custom
  • In the field, put this formula: =IF(AND(LEN(A1)=2,ISNUMBER(VALUE(LEFT(A1,1))),ISTEXT(RIGHT(A1,1))),TRUE,FALSE)
  • In the tab Error Alert, change the dialog to explain to the user what he should do, something like:

You have to enter a number followed by a letter.

Btw, you could add a check with an UPPERCASE test.

[EDIT] Also have a look at brettj's answer for a similar but optimized solution

这篇关于Excel:数据验证,如何强制用户输入一个2 char长的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆