跳到主要內容

如何在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。 然後按 Enter 鍵,然後選擇單元格D1,將填充手柄拖到要應用此公式的範圍。 看截圖:

doc-convert-text-to-formula1


箭頭藍色右氣泡 使用Kutools for Excel將文本字符串轉換為公式

如果您不喜歡使用上面的代碼,可以申請 Excel的Kutools將文本轉換為公式 功能,借助它的幫助,您還可以立即將文本字符串轉換為公式。

Excel的Kutools 包括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中將公式轉換為文本字符串?

最佳辦公生產力工具

熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

kte選項卡201905


Office選項卡為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