跳到主要內容

如何在Excel中選定單元格的中間添加文本?

假設您有一個由開頭字母G和其他數字組成的數據列表,現在您要在整個列表的第一個字母G之後添加另一個字母D。 請參見下面顯示的屏幕截圖。

您如何才能做到這一點? 將字母逐個添加到單元格似乎在您的工作中浪費時間。 在本文中,我們將向您展示如何使用有效的方法在Excel中選定單元格的中間添加文本。

使用公式在所選單元格的中間添加文本
使用VBA代碼在所選單元格的中間添加文本
使用Kutools for Excel在所選單元格的中間添加文本


使用公式在所選單元格的中間添加文本

在本節中,我們將為您提供在選定單元格的中間添加文本的公式。 請執行以下操作。

1.此方法應在幫助列中完成。 選擇與原始數據相鄰的空白單元格,在這裡我選擇單元格B2。

2.複製並粘貼公式 = LEFT(A2,1)&“ D”&MID(A2,2,100) 進入編輯欄,然後按 Enter 鍵。 看截圖:

筆記:

  • 1)。 在公式中,數字1表示將在單元格的第一個字符之後添加文本。
  • 2)。 數字2和100表示​​將在新插入的文本之後添加原始單元格的第二到百分之一的字符。
  • 3)。 如果要在第二個字符後添加文本,請在公式中將數字1更改為2,將2更改為3。
  • 4)。 字符“ D”是您要添加到單元格中的文本。 請根據您的需要進行更改。

3.選擇單元格B2,將“填充手柄”向下拖動到要用此公式覆蓋的單元格。 您可以看到文本被添加到整個列表的單元格中間。

保養竅門:除了上述公式外,您也可以應用此公式 = REPLACE(A2,2,0,“ D”),(數字2表示您要插入文本的位置,字母D表示您要添加的文本,可以將其更改為所需的文本),然後按Enter鍵以獲取結果。


將文本添加到Excel中所有選定單元格的開頭或結尾:

Kutools for Excel的 添加文本 實用程序可以將指定的文本快速添加到Excel中所選內容的單元格的開頭或結尾。
立即下載Kutools for Excel的全功能30天免費試用版!


使用VBA代碼在所選單元格的中間添加文本

此外,您可以使用VBA代碼在所選單元格的中間添加文本。

1.請按 其他 + F11 打開 Microsoft Visual Basic應用程序 窗口。

2。 點擊 插入 > 模塊。 然後將下面的VBA代碼複製並粘貼到代碼編輯器中。

VBA代碼:將第一個字符後的文本添加到數據列表中

Sub AddString()
	Dim Rng As Range
	Dim WorkRng As Range
	On Error Resume Next
	xTitleId = "KutoolsforExcel"
	Set WorkRng = Application.Selection
	Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
	For Each Rng In WorkRng
		Rng.Value = VBA.Left(Rng.Value, 1) & "D" & VBA.Mid(Rng.Value, 2, VBA.Len(Rng.Value) - 1)
	Next
End Sub

3。 按 F5 鍵運行代碼,並在彈出窗口中 Kutoolsfor Excel 對話框中,選擇要向其添加文本的範圍,最後單擊 OK 按鈕。

現在,將指定的文本添加到所選單元格的第一個字符之後。

備註:在上面的代碼中,您將在單元格中的第一個字符之後插入一個特定的值,如果在此腳本的第二個字符之後添加文本,則可以將數字1和2更改為數字2和3 VBA.Left(Rng.Value,1)&“ D”&VBA.Mid(Rng.Value,2,VBA.Len(Rng.Value)-1),字母D是您要插入的新文本。


使用Kutools for Excel在所選單元格的中間添加文本

我們必須承認上述兩種方法對我們來說很不方便。 在這裡,我將向您展示 添加文本 的效用 Excel的Kutools,使用此實用程序,您可以輕鬆地指定列表的中間位置,然後將某些文本同時添加到整個列表的該位置。

申請前 Excel的Kutools首先下載並安裝.

1.選擇要在單元格中間添加文本的列表,然後單擊 庫工具 > 文本 > 添加文本。 看截圖:

2。 在裡面 添加文本 對話框中,輸入要添加到單元格中的文本 文本 框,選中要添加文本的位置 指定 選項(在這裡我輸入數字1),然後點擊 OK 按鈕。 (您可以在右側的框中立即預覽添加結果)

備註:要一次在所選單元格的多個位置添加文本,您可以在逗號分隔的位置指定位置 指定 框。 看截圖:

現在,將指定的文本添加到所選列表中的第一個字母之後。

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


使用Kutools for Excel在所選單元格的中間添加文本


相關文章:.

最佳辦公生產力工具

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

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

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Boa tarde, tudo bem ?

Eu testei as duas fórmulas e não funcionaram. Inclusive testei também no mesmo cenário descrito no texto e também não funcionou. Poderia verificar se falta algo na fórmula do excel ?
This comment was minimized by the moderator on the site
Tive o mesmo problema, mas segui pela resposta que enviaram aqui, a formula para o excel em português seria =ESQUERDA(A2;1) & "D" & EXT.TEXTO(A2;2;100)

A parte da fórmula que dá o erro seria o "MID" que precisa ser substituído por "EXT.TEXTO"
This comment was minimized by the moderator on the site
Hi Matheus C.,
If you are using the Excel version in a different language than English, please convert the formula from English to the language you are currently using.
You can translate the formula in this page: https://de.excel-translator.de/translator/
This comment was minimized by the moderator on the site
Hi Vick,
The formula provided in the post can only be applied in English system environment Excel. If you have Excel in a different language than English, please convert the formula from English to the language you are currently using.
It seems that you are using the Excel in Portuguese language system. You need to change the commas in the formula to semicolons.
You can translate the formula in this page: https://de.excel-translator.de/translator/
This comment was minimized by the moderator on the site
TRIMAKASIH KAK, SANGAT MEMBANTUUUU
This comment was minimized by the moderator on the site
This seems complicated. For the originally stated problem why not just do a search for G and replace all with GD?
This comment was minimized by the moderator on the site
Because you might want to insert a specific character at a certain index of the string. What if they weren't all G's? This was just to provide an example of how it works.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations