Excel – 如何获得expression文本而不是价值

我遇到一大堆Excel数据的问题。 还有一个人input了这样的数据:

A 10 10:12 11:12:15 

我的任务是把它转换成这样的东西:

 B Pig Pig:Koala Dog:Koala:Bird 

我试图用替代品:

 = SUBSTITUTE(A1, "10", "Pig") 

但问题是,Excel将A列中的那些值识别为其他数据types(数字,时间…),并且SUBSTITUTE不适用于这些types。

我怎么能解决这个问题?

谢谢。

这个函数将返回一个与excel显示内容相匹配的string。

 Option Explicit Function ToText(r As Range) As String If r.Count <> 1 Then ToText = "#ERR!" Exit Function End If ToText = IIf(r.NumberFormat = "General", CStr(r.Value), Format(r.Value, r.NumberFormat)) End Function 

例如,如果10:11:12在A1中,那么excel认为是一个时间,并且这样格式化,那么=ToText(A1)将返回string10:11:12 ,然后您可以像操作那样操作任何其他文字

把它放在电子表格( ALT + F11 )的一个模块中,这样该函数就可以用于excel

 Select column A from first to last record and right click on that, then change the format by clicking Format cells... and choose whatever format you want... 

喜欢

在这里输入图像说明

然后使用SUBSTITUTE(A1,“10”,“Pig”)方法