跳到主要內容

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

作者:凱莉 最後修改時間:2024-05-08

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


影片:在 Excel 中新增文本


使用快速填充將文字添加到所有單元格的開頭/結尾

Excel 中的快速填充是一種智慧工具,可在偵測到模式時自動填入資料。當您有所需輸出的範例時,此功能對於向單元格添加文字特別有用。

假設你需要 在 A 列的姓名前面加上“Dr.”。以下是如何使用快速填充來實現此目的:

  1. 確保您的資料位於一列中,並且下一列為空。

  2. 輸入第一個範例 “博士。” 新增到下一列的第一個儲存格中,然後點擊 Enter.

  3. 媒體推薦 按Ctrl + E 自動填入列中的其餘儲存格 “博士。” 為名稱加上前綴。

    小提示: 您也可以點擊 數據 功能區上的選項卡,然後選擇 Flash填充 如果您喜歡使用功能區介面進行 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),然後合併兩個儲存格。 小提示: 前置文字的儲存格位址以 $ 符號鎖定,以防止複製公式時發生變更。

  • 將文字附加到單元格現有內容的末尾,只需反轉公式結構即可。例如,要在儲存格 A2 中的內容末端新增“- Class A”,請使用下列任一公式:
    =A2&" - Class A"
    =CONCATENATE(A2, " - Class A")
    =CONCAT(A2, " - Class A")


使用 AI 將文字新增到所有儲存格的開頭/結尾

AI助理功能 Excel的Kutools 是智慧數據處理的重大飛躍。它利用人工智慧來分析您的請求並透過簡單的命令執行複雜的任務。

預先添加文本,例如 “博士。” 到您選擇的單元格,只需選擇單元格,然後按一下 庫工具 > 人工智慧助手,並告訴 Kutools AI Aide: 在每個選定的單元格之前加上“Dr.”。它將立即理解並呈現 執行 按鈕。單擊它,更改將立即應用。

筆記:

  • 如果結果不是您所期望的並且您希望撤消更改,請按一下 不滿意 按鈕來恢復您的操作。
  • 將文字(例如“AA”)附加到所有選定單元格的末尾,將您的請求調整為 添加“AA” 每個選定的儲存格.
  • 想要訪問 人工智慧助手 公用事業? 下載 Excel的Kutools 現在! 除此之外,Kutools 還擁有 300 多個其他功能,並提供 30 天免費試用。 不要等待,今天就來試試吧!

使用 VBA 將文字新增到所有儲存格的開頭/結尾

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

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

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

    • 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 鍵運行巨集。

結果

  • 如果執行第一個 VBA,則該值 “排除-” 將會被加入到所有選取儲存格的內容之前。

  • 如果執行第二個 VBA,則該值 “-XS” 將附加到所有選取儲存格的內容中。

小提示: 如果你願意 將修改後的值放入右側相鄰列中 不要直接將文字新增到原始值,而是使用以下程式碼:
  • 將文字新增至儲存格內容之前並放置在下一列:

    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
  • 將文字附加到儲存格內容並放置在下一列中:

    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 安裝後,選擇一個或多個要新增指定文字的範圍,然後按一下 庫工具 > Text > Add Text。 在 Add Text 對話框,請執行以下操作:

  1. 輸入您要新增的文字。
  2. 選擇所需的文字放置位置選項。 您可以在預覽窗格中預覽結果。
  3. 擊中 OK.

提示:
  • 在提供的螢幕截圖中, “2024” 已在文字方塊中輸入 最後一個字符之後 已選擇選項。在將變更套用到所選範圍之前,您可以預覽文字在每個儲存格中的顯示方式。
  • 如果您檢查 Skip non-text cells 選項,該工具不會將指定的文字新增至包含非文字內容的儲存格。

注意: 想要訪問 添加文本 公用事業? 下載 Excel的Kutools 現在! 除此之外,Kutools 還擁有 300 多個其他功能,並提供 30 天免費試用。 不要等待,今天就來試試吧!


使用自訂格式以視覺方式將文字新增至所有儲存格的開頭/結尾

Excel 中的自訂格式是一項強大的功能,可讓您 直觀地修改單元格顯示 而不實際改變細胞的原始內容。它對於添加對於解釋至關重要但不應該幹擾計算的單位或標識符特別有用。

假設您有一列代表您想要的權重的數字 顯示每個數字後附加單位“kg” 出於計算目的而無需更改實際數字。請依照以下步驟操作:

  1. 選擇包含權重的儲存格。您可以選擇電子表格中的範圍、整列或特定儲存格。

  2. 按住 Ctrl + 1 鍵打開 單元格格式 對話。 或者,您可以右鍵單擊選定的儲存格並選擇 單元格格式 從上下文菜單。
  3. 單元格格式 對話框,在 聯繫電話 標籤,請:
    1. 選擇 習俗 從左側的類別清單中。
    2. 類別 下的輸入框 習俗,輸入以下格式代碼: #“ 公斤”. 然後您可以在中預覽新格式 樣本 框以在應用前查看其外觀。
    3. 點擊 OK.

結果

現在,您選擇的每個數字都將顯示為 “公斤” 附加,而單元格中的實際值保持不變,因此涉及這些單元格的任何計算仍將使用純數值數據,而無需 “公斤” 文本。

筆記:

  • 格式代碼 #“ 公斤” 視覺上附加 “ 公斤” 對於所有包含數字的儲存格,您可以按如下方式自訂:
    • 更換 kg 將要新增的文字放在引號內。
    • 如果您的儲存格包含文字並且您想要將特定文字附加到其中,請替換 # (數字符號)與 @ (“at”符號)在格式代碼中。

  • 直觀地將文字添加到單元格的開頭,先於 # 在您的格式代碼和文字中。例如,輸入 "文字 "# 在格式框中將預先新增 "文字 " 到所有數位單元格。

在每個單元格內的第 N 個字元後插入文本

在本節中,我們將探討兩種在每個單元格中的第 N 個字元後面插入特定文字的方法:一種使用 替換公式 另一個帶有 多功能工具。作為範例,我們將展示 如何在第 5 個字元後插入連字符 (-).


使用 REPLACE 公式在第 N 個字元後插入文字

要使用 REPLACE 函數在單元格中的第 N 個字元之後插入特定文字或字符,我們將遵循下面描述的模式。

=REPLACE(cell, N+1, 0, "text")

這個公式背後的邏輯是替換 0 (無)字符 細胞 在 (N + 1)th 位置與 “文本”。例如,要 在第 5 個字元後插入連字符 (-),我將使用下面的公式:

=REPLACE(A2, 6, 0, "-")


使用 Kutools for Excel 在第 N 個字元後插入文字

通過應用 Kutools for Excel's Add Text 函數中,您不僅可以將指定文字新增至儲存格的開頭或結尾,還可以新增到儲存格內的指定位置。

在第 5 個字元後插入連字符 (-),選擇一個或多個要插入連字符的範圍,然後按一下 庫工具 > Text > Add Text。 在 Add Text 對話框,請執行以下操作:

  1. 輸入連字符 (-) 在文字方塊中。
  2. 點擊 指定位置 選項,然後輸入 5 在第 5 個字元後插入連字符。 您可以在預覽窗格中預覽結果。
  3. 擊中 OK.

注意: 想要訪問 添加文本 公用事業? 下載 Excel的Kutools 現在! 除此之外,Kutools 還擁有 300 多個其他功能,並提供 30 天免費試用。 不要等待,今天就來試試吧!


在特定字元之前/之後新增文本

在本節中,我們將探討兩種在 Excel 儲存格中的特定字元之前或之後附加文字的方法:一種使用 替代公式 另一個帶有 多功能工具。為了方便說明,我們將進行示範 如何在儲存格內容中的連字號 (-) 前後插入“(EO)”.


使用 SUBSTITUTE 公式在特定字元之前/之後插入文字

要使用 SUBSTITUTE 函數在單元格中的特定字符之前或之後插入文字或字符,我們將遵循下面描述的模式。

  • 前置文字 之前 特定字元(“anchor_text”):

    =SUBSTITUTE(cell, "anchor_text", "added_text & anchor_text", 1)

  • 附加文字 特定字元(“anchor_text”):

    =SUBSTITUTE(cell, "anchor_text", "anchor_text & added_text", 1)

公式背後的邏輯是替換 “錨文本”細胞 “新增的文字和錨文本” or “錨文本和添加文字”,以便插入 “新增的文字” 之前或之後 “錨文本”.

例如,插入“(EO)” 之前 儲存格內容中的連字號 (-),使用下列公式:

=SUBSTITUTE(A2, "-", "(EO)-", 1)

提示:
  • 數量 1 SUBSTITUTE 公式中的指令告訴 Excel 僅取代儲存格 A2 中第一次出現的連字號 (-)。如果有多個連字符並且您希望替換不同的連字符,請調整此數字以匹配您要定位的特定實例。添加“(EO)” 每個連字符之前,完全刪除實例號:
    =SUBSTITUTE(A2, "-", "(EO)-")
  • 插入“(EO)” 連字號 (-) 之後,使用以下公式:
    =SUBSTITUTE(A2, "-", "-(EO)", 1)

使用 Kutools for Excel 在特定字元之前/之後插入文字

Kutools for Excel's Add Text 功能可讓您輕鬆在儲存格內的特定字元之前或之後新增文字。

在連字號 (-) 前插入“(EO)” 在儲存格內容中,選擇一個或多個要進行此修改的範圍,然後按一下 庫工具 > Text > Add Text。 在 Add Text 對話框,請執行以下操作:

  1. 類別 (EO) 在文本框中。
  2. 點擊 正文前 選項,然後輸入連字符 (-) 在對應的輸入框中。 您可以在預覽窗格中預覽結果。
  3. 擊中 OK 在連字號之前插入 (EO)。

注意: 想要訪問 添加文本 公用事業? 下載 Excel的Kutools 現在! 除此之外,Kutools 還擁有 300 多個其他功能,並提供 30 天免費試用。 不要等待,今天就來試試吧!


以上就是Excel中刪除巨集相關的全部內容。 我希望本教程對您有所幫助。 如果您想探索更多 Excel 提示和技巧, 請點擊這裡 訪問我們廣泛收集的超過數千個教程。

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