string 如果字符计数大于值,则截断 Excel 单元格内的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10105819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Truncate a string inside an Excel cell if the char count is greater than than a value
提问by user1326510
In Excel, for each row of the sheet I have various length strings (a1,a2,a3...). In cell B2 I have =Length(A1)
to count the chars inside the string.
在 Excel 中,对于工作表的每一行,我都有不同长度的字符串(a1、a2、a3...)。在单元格 B2 中,我必须=Length(A1)
计算字符串中的字符数。
I need a formula/function that can truncate all strings in column A which have a character count > 20 Something like:
我需要一个公式/函数,它可以截断 A 列中字符数 > 20 的所有字符串,例如:
$string = THIS IS A LONG STRING I WANT TO TRUNCATE IF EXCEEDS 20 CHARS;
if ($string > 20)
{
COUNT 20 CHARS FROM THE BEGINNING OF STRING AND CUT THE REST
}
else
{
skip
}
回答by Alex K.
You can just read the 1st 20 characters, it doesn't matter if there are fewer;
您可以只读取第 1 个 20 个字符,少则无所谓;
=left(A1, 20)
回答by Rockstart
Use this,
用这个,
=LEFT(DataCell,20)
eg:
例如:
=LEFT(A1,20)
回答by Francis P
Use the Len
function for Length and Left
function to use only the first 20 caracters:
使用Len
Length 和Left
function 的函数仅使用前 20 个字符:
Dim myString As String
If (Len(myString) > 20) Then
myString = Left(myString, 20)
End If