跳到主要內容

如何在Excel中所有單元格的開頭或結尾添加文本?

有時,您可能會發現自己需要在所選內容的每個儲存格中新增或附加相同的特定文字。 為每個單元手動執行此操作可能非常乏味且耗時。 幸運的是,有幾種更簡單的方法可以實現此目的,使您可以更有效地將相同的文字添加到所選內容中所有單元格的開頭或結尾。


使用公式將指定的文本添加到所有單元格的開頭/結尾

在本節中,我們將學習如何使用 Excel 公式在儲存格的開頭或結尾輕鬆插入特定文字或字元。

將指定文字新增至儲存格的開頭

若要將文字新增至 Microsoft Excel 中儲存格的開頭,您可以使用 Excel 公式將指定的字串與儲存格參考連結。假設你需要 將「Class A:」新增到 A 列中的名稱前面。以下是如何應用公式來實現此目的:

  1. 選擇要輸出名字前綴為“的儲存格”A類: ".

  2. 根據您的喜好輸入任何這些公式並點擊 Enter 查看第一個結果(這裡我以第一個公式為例):
    ="Class A: "&A2
    =CONCATENATE("Class A: ", A2)
    =CONCAT("Class A: ", A2)
    小提示: 在這些公式中,「A類: " 是新增到名稱中的前綴,並且 A2 是包含您要修改的名稱的第一個儲存格。隨意替換”A類: ”並調整 A2 以滿足您的特定需求。

  3. 將填充柄向下拖曳到要套用此公式的儲存格。

筆記:

  • 公式不會修改原始資料。
  • 為簡單起見,請將要新增的文字放置到特定儲存格中(例如 E2),然後合併兩個儲存格。 小提示: 前置文字的儲存格位址以 $ 符號鎖定,以防止複製公式時發生變更。


將指定文字新增至儲存格末尾

若要將文字附加到 Microsoft Excel 中的儲存格結尾,您可以使用 Excel 公式將儲存格參考與指定字串連接。想像一下你需要 將「-Class A」附加到 A 列中的名稱。請依照以下步驟有效利用公式:

  1. 選擇您希望名稱後綴為“的儲存格” - A級” 來顯示。

  2. 根據您的喜好選擇其中一個公式並按 Enter 查看結果(這裡,我將使用第一個公式進行演示):
    =A2&" - Class A"
    =CONCATENATE(A2, " - Class A")
    =CONCAT(A2, " - Class A")
    小提示: 在這些公式中,「 - A級" 是附加到名稱後的文本,並且 A2 指包含您要修改的名稱的初始儲存格。我們鼓勵您更換“ - A級”並調整 A2 根據需要滿足您的特定要求。

  3. 透過向下拖曳填充手柄將公式擴展到所需的單元格。

筆記:

  • 公式不會修改原始資料。
  • 為簡單起見,請將要新增的文字放置到特定儲存格中(例如 E2),然後合併兩個儲存格。 小提示: 前置文字的儲存格位址以 $ 符號鎖定,以防止複製公式時發生變更。


將相同的文本添加到 Excel 中每個單元格的特定位置

如何將文本或字符添加到多個單元格的開頭,或者如何將文本或字符添加到單元格的末尾或在現有文本之間插入文本或字符? 用 添加文本 Kutools for Excel實用程序,您可以快速應用以下操作:。 點擊即可獲得 30 天的全功能免費試用!
doc添加文本6
 
Kutools for Excel:擁有超過 300 個方便的 Excel 插件,在未來 30 天內免費試用,沒有任何限制。

使用VBA將指定的文本添加到所有單元格的開頭/結尾

在本節中,我們將探索一種簡單的 VBA 方法,將指定的文字直接新增到一個或多個選取範圍內的所有儲存格的開頭或結尾。

將指定文字新增至儲存格的開頭
  1. 選擇要將指定文字新增至所有儲存格開頭的範圍。
  2. 按住 Alt + F11鍵 在Excel中打開鍵 Microsoft Visual Basic for Applications 窗口。
  3. 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到 模塊 窗口。
    Sub PrependToSelectedCells()
        Dim c As Range
        For Each c In Selection
            If c.Value <> "" Then c.Value = "EXCL-" & c.Value 
        Next
    End Sub

    注意: 此程式碼為所有選取的儲存格新增前綴 “排除-”。確保在將程式碼中的範例文字應用到工作表之前將其替換為您需要的實際文字。

  4. F5 運行此宏的鍵。

結果

價值 “排除-” 將會被加入到所有選取儲存格的內容之前。

小提示: 如果你願意 將修改後的值放入右側相鄰列中 不要直接將文字新增到原始值的開頭,而是使用以下程式碼:

Sub PrependToRightOfSelectedCells()
    Dim c As Range
    For Each c In Selection
        If c.Value <> "" Then c.Offset(0, 1).Value = "EXCL-" & c.Value
    Next c
End Sub

將指定文字新增至儲存格末尾
  1. 選擇要將指定文字新增至所有儲存格末端的範圍。
  2. 按住 Alt + F11鍵 在Excel中打開鍵 Microsoft Visual Basic for Applications 窗口。
  3. 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到 模塊 窗口。
    Sub AppendToSelectedCells()
        Dim c As Range
        For Each c In Selection
            If c.Value <> "" Then c.Value = c.Value & "-XS"
        Next
    End Sub

    注意: 該巨集附加 “-XS” 每個選定單元格的內容。確保更換 “-XS” 在工作表中執行巨集之前,使用您希望附加到儲存格內容的特定後綴。

  4. F5 運行此宏的鍵。

結果

價值 “-XS” 將附加到所有選取儲存格的內容中。

小提示: 如果你願意 將修改後的值放入右側相鄰列中 不要直接將文字新增到原始值的末尾,而是使用以下程式碼:

Sub AppendToRightOfSelectedCells()
    Dim c As Range
    For Each c In Selection
        If c.Value <> "" Then c.Offset(0, 1).Value = c.Value & "-XS"
    Next c
End Sub

使用Kutools for Excel將指定的文本添加到所有單元格的開頭/結尾

Excel的Kutools's Add Text 工具將幫助您快速將指定的文本添加到所選內容中每個單元格的開頭或結尾。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

安裝後 Kutools for Excel,請執行以下操作:(立即免費下載Kutools for Excel!)

1。 選擇您要添加指定文本的範圍。

2。 點擊 庫工具 > Text > Add Text…。 看截圖:

doc添加特定文本11

3. 。 In在 Add Text 對話框中,輸入您需要添加的文本 Text 框。

(1.)如果檢查 Before first character 來自 Position 部分,並且特定文字將添加在所有單元格值的前面。

doc添加特定文本6

(2.)如果檢查 After last character 來自 Position 部分,特定文字將添加到單元格值的末尾。

doc添加特定文本7

筆記:

1. Excel的Kutools's Add Text 工具可讓您預覽“預覽”部分中所選內容的更改。

2.如果您檢查 Skip non-text cells 選項,此工具不會在具有非文本內容的單元格中添加指定的文本。


使用Kutools for Excel將指定的文本添加到所有單元格的指定位置

應用 Kutools for Excel's Add Text 功能,您不僅可以將指定的文本添加到單元格的開頭或結尾,還可以將指定的文本添加到單元格的指定位置。

安裝後 Kutools for Excel,請執行以下操作:(立即免費下載Kutools for Excel!)

1。 選擇要向其添加文本的範圍,然後單擊 庫工具 > Text > Add Text.

2。 “ Add Text 將顯示對話框,並輸入指定的文本並在框中指定要插入文本的特定位置。 看截圖:

我在這裡輸入3 Specify textbox表示在字符串的第三個字符之後添加文本。

doc添加特定文本8

3。 點擊 Ok or Apply。 指定的文本已添加到單元格的指定位置。 看截圖:

doc添加特定文本9

小提示:

(1)在 Specify 文本框,您可以輸入逗號分隔的數字以同時在多個位置添加文本。
doc添加特定文本12

(2)如果要在每個大寫字母之前添加文本,則 1st letter is uppercase 選項 Add Text 實用程序可以為您提供幫助。
doc添加特定文本10

另外,您可以在每個小寫字母或每個數字字母之前添加文本。

單擊立即下載並免費試用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 (55)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Bonjour, J'ai besoin d'aide. J'ai un tableau excel dans lequel je veux dans une de mes colonnes que lorsque j'écris NOK la cellule se colore en rouge et les caractères en blanc.
En VBA J'ai déjà tout essayé comme message mais j'ai toujours une erreur. Mon problème se situe au niveau de la première ligne car je ne sais pas quoi écrire. Quand j'inscris NAME il ne fait rien. Quand j'inscris Value il ne fait rien. J'ai essayé TEXTBOX et le nom de la colonne CAISSE mais j'ai toujours une erreur.

If cell.Textboxcaisse = NOK Then
cell.Interior.ColorIndex = 3
cell.Font.ColorIndex = 2
cell.Font.Bold = True
End If
Next
For Each cell In Range("r3:r500")
If cell.Name = OK Then
cell.Interior.ColorIndex = 2
cell.Font.ColorIndex = 1
cell.Font.Bold = True
End If
Next

Merci pour votre aide.
This comment was minimized by the moderator on the site
Hi there,

Do you mean that you want the fill color to turn red and font color to turn white as long as the cell's content is NOK? So, if 10 cells have NOK as content, and the 10 cells are in the column you mentioned, the fill color and font color of all the 10 cells will change?

Also, can you speak English? So I can better understnd your situation. And it will be better if you attach the file with the VBA you created. So that we can help you revise it with higher efficiency.

Thanks in advance.
Amanda
This comment was minimized by the moderator on the site
Thank you!
This comment was minimized by the moderator on the site
the VBA code worked perfectly on Office for Mac
This comment was minimized by the moderator on the site
Me has quitado varias horas de trabajo de encima, mil gracias!!!
This comment was minimized by the moderator on the site
thanks a lot dear for sharing information.
This comment was minimized by the moderator on the site
Thank you! Apend and pre-pend macro works great
This comment was minimized by the moderator on the site
I am trying to change a date formula from mm/dd/yyyy to dd/mm/yyyy. The leading zeros for months and dates less than 10 (two digits) are going away. Anyone have tips on how to easily put them back. I tried using the =month, =day, =year formulas and concatenating them. However, the leading zeros are dropping off. I would manually have to put in the leading zeros. Is there an easy way to do this? We are going to have approximately 1,000 rows of data on our file each month.
This comment was minimized by the moderator on the site
Hi, Amanda, if you want to convert date from mm/dd/yyyy to dd/mm/yyyy, this article https://www.extendoffice.com/documents/excel/4646-excel-convert-dd-mm-yyyy-to-mm-dd-yyyy.html can help you, it list two easiest ways for solving this job.
This comment was minimized by the moderator on the site
I want to make a formula that show in cell text "Profit" when another cell show +digit, and show in that cell "Loss" when another that cell show -digit
This comment was minimized by the moderator on the site
Hi, Manik, use this =IF(B1>0, "Profit", "Loss")
This comment was minimized by the moderator on the site
Thanks a lot!! I was initially using Access but this is so much easier.
This comment was minimized by the moderator on the site
Hello, i want to add text in a formula;

current cell value: ='DAM91-SVC'!$C$47
i want to add text: [MHSV Sales Report 2017 (JAN-DEC).xlsx]

therefore the cell value should read like this in the end: ='[MHSV Sales Report 2017 (JAN-DEC).xlsx]DAM91-SVC'!$C$47

please tell me how will this be done.
thank you
total 1800 cell count need alteration.
This comment was minimized by the moderator on the site
Hello, sorry to read your question so late. Here is a solution but you need to free download Kutools for Excel.

Using the Convert Formula to Text utility to convert the formula cell to text, then apply Add Text utility to add the text string in the Specify position(1), then click Ok. After all cells have been added text, conver them to formula by click Kutools > Content > Convert Text to Formula.
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