跳到主要内容

如何在Excel中将文本字符串转换为公式?

如果有很多= A1 + B1格式的文本字符串,则需要将这些文本字符串转换为真实公式并在工作表中计算它们的值,不幸的是,没有直接的方法可以在Excel中解决。 但是,在这里我可以为您介绍一些有趣的技巧。

使用用户定义函数将文本字符串转换为公式

使用 Kutools for Excel 将文本字符串转换为公式


箭头蓝色右气泡 使用用户定义函数将文本字符串转换为公式

以下简短的VBA代码可以帮助您解决将文本转换为公式的问题,具体步骤如下:

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic for Applications窗口.

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.

VBA代码:将文本字符串转换为公式

Function Eval(Ref As String)
Application.Volatile
Eval = Evaluate(Ref)
End Function

3。 保存此代码并返回到您的工作表,输入此公式 = Eval(C1) 放入空白单元格(C1 包含要转换为公式的文本字符串单元格),请参见屏幕截图:

doc-convert-text-to-formula1

4。 然后按 输入 键,然后选择单元格D1,将填充手柄拖到要应用此公式的范围。 看截图:

doc-convert-text-to-formula1


箭头蓝色右气泡 使用 Kutools for Excel 将文本字符串转换为公式

如果您不喜欢使用上面的代码,可以申请 Kutools for Excel将文本转换为公式 功能,借助它的帮助,您还可以立即将文本字符串转换为公式。

Kutools for Excel 包括300多个便捷的Excel工具。 30天免费试用,不受限制。 立即获取.

在安装Kutools for Excel之后,请按照以下步骤操作:

1。 选择您要转换的文本字符串。

2。 点击 库工具 > 内容转换器 > 将文本转换为公式,请参见屏幕截图:

doc-convert-text-to-formula1

3。 而且您所有选择的文本字符串都已转换为真实公式,并获得其值。 查看屏幕截图:

doc-convert-text-to-formula4 -2 doc-convert-text-to-formula5

要了解有关此文本转换为公式功能的更多信息。


相关文章:

如何在Excel中将公式转换为文本字符串?

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I am finding this to be not working properly. As everyone else has said (and I could not see a satisfactory solution), it does not work when trying to pull in stuff from other worksheets in the same workbook. It's frustrating and I am having to give up on this and find another solution. So the Google search continues!
This comment was minimized by the moderator on the site
Thank you very much!!! GREAT IDEA!!!
This comment was minimized by the moderator on the site
Hello
For the first defined function way, I have a problem.
when the resources for concatenate function are in another worksheet, Eval function works properly when that resource worksheet is open, But immediately when I close that resource worksheet, Eval function Not working. How I can change the codes for eval function to use closed resource worksheets?
This comment was minimized by the moderator on the site
Hello Johnny
about Hussein’s issue, if the external workbook is closed INDIRECT gives #REF! error. Do you have other solution?
This comment was minimized by the moderator on the site
use indirect only works with open workbooks.


solution is to use indirect.ext from morefunc.


regards,
Hasan nasralla
This comment was minimized by the moderator on the site
Hi Hussein,

Just use the INDIRECT function in Excel. Does the same thing.
This comment was minimized by the moderator on the site
Greetings, the above code works perfectly inside the same workbook across different sheets, but in case i have a cell reference to an external workbook it returns #VALUE!. the formulas were calculating normally earlier.
Example for the formula can't be evaluated correctly: IFERROR(INDEX('[Tracking-OSP Outside Riyadh-07-09-2017.xlsx]Tracking WO'!$U$3:$U$19000,MATCH(A3&"",'[Tracking-OSP Outside Riyadh-07-09-2017.xlsx]Tracking WO'!$B$3:$B$19000,0)),INDEX('[Tracking-OSP Outside Riyadh-07-09-2017.xlsx]Tracking WO'!$U$3:$U$19000,MATCH(value(A3),'[Tracking-OSP Outside Riyadh-07-09-2017.xlsx]Tracking WO'!$B$3:$B$19000,0))).
This comment was minimized by the moderator on the site
The replace = with = works, so relieved. Thank you to whoever discovered and shared this nugget of Excel gold.
This comment was minimized by the moderator on the site
To clarify my other comment, I mass replaced the "=" character with the same "=" character, and that made the strings turn into formulas.
This comment was minimized by the moderator on the site
Hi Rich,
I'm just reading you comment on turning text into a formula. It seems that the function as mentioned above is not working. I'm not really a programmer but what i did is converting a formula into a text and in the text i have to replace a few values and combine it again in one text but now i need to convert it back into a formula. Could you give me a tip.
Regards
Frans
This comment was minimized by the moderator on the site
I don't know if this would always work, but I had a number of cells that had formulas stored as text strings. I did a full worksheet find replace on the "=" character, and all of my strings converted to formulas with that one action.
This comment was minimized by the moderator on the site
Thank you. Works well with the user defined function... I could do what I could not using the default functions of INDIRECT, ADDRESS et al provided. It fell short when I had a range to be input.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations