提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何在一系列單元格中加粗所有特定單詞?

doc粗體特定文本1

在Excel中, 查找和替換 函數可以幫助我們找到任何特定的文本,並為整個單元格提供粗體或任何其他格式。 但是,你有沒有試過只加粗單元格中的特定文本而不是整個單元格,如下面的截圖所示:

使用VBA代碼粗體顯示一系列單元格中的所有特定單詞


箭頭藍色右泡 使用VBA代碼粗體顯示一系列單元格中的所有特定單詞


以下VBA代碼可能會幫助您僅粗體顯示單元格內容中的特定文本,請按照以下步驟操作:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,並將以下代碼粘貼到 模塊 窗口。

VBA代碼:單元格範圍內的粗體特定文本

Sub FindAndBold()
'Updateby Extendoffice 20160711
    Dim xFind As String
    Dim xCell As Range
    Dim xTxtRg As Range
    Dim xCount As Long
    Dim xLen As Integer
    Dim xStart As Integer
    Dim xRg As Range
    Dim xTxt As String
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("Please select data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    On Error Resume Next
    Set xTxtRg = Application.Intersect(xRg.SpecialCells(xlCellTypeConstants, xlTextValues), xRg)
    If xTxtRg Is Nothing Then
        MsgBox "There are no cells with text"
        Exit Sub
    End If
    xFind = Trim(Application.InputBox("What do you want to BOLD?", "Kutools for Excel", , , , , , 2))
    If xFind = "" Then
        MsgBox "No text was listed", vbInformation, "Kutools for Excel"
        Exit Sub
    End If
    xLen = Len(xFind)
    For Each xCell In xTxtRg
        xStart = InStr(xCell.Value, xFind)
        Do While xStart > 0
            xCell.Characters(xStart, xLen).Font.Bold = True
            xCount = xCount + 1
            xStart = InStr(xStart + xLen, xCell.Value, xFind)
        Loop
    Next
    If xCount > 0 Then
        MsgBox "number of " & CStr(xCount) & " text be bolded!", vbInformation, "Kutools for Excel"
    Else
        MsgBox "Not find the specific text!", vbInformation, "Kutools for Excel"
    End If
End Sub

3。 然後按 F5 鍵來運行此代碼,並彈出一個提示框來提醒您選擇要加粗的數據范圍,請參閱屏幕截圖:

doc粗體特定文本2

4。 然後點擊 OK,會彈出另一個框提醒您輸入想要在單元格中加粗的特定文本,請參閱截圖:

doc粗體特定文本3

5。 輸入文字後,請點擊 OK 按鈕,並且您指定的所有文本都被加粗顯示在所選範圍內,請參閱屏幕截圖:

doc粗體特定文本4


Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Sherry Fox · 4 months ago
    I attempted to run this code and just got an error..."Compile Error: Wrong # of arguments or invalid property assignment". Below is the image of the error message and the breakpoint of the code.
    • To post as a guest, your comment is unpublished.
      skyyang · 4 months ago
      Hello, Sherry,
      I can not see your screenshot, please upload it again.
      Thank you!
  • To post as a guest, your comment is unpublished.
    Pedro Martins · 1 years ago
    Hello, its possible to search multiple text and bold that text PLUS that cell line. (I have 1 cell with 5 lines, i want to bold the line if find "1º", if rest like "2º" "3º" , "number + º " bold only number.)

    Other need is:
    If find "1º" bold that cell line
  • To post as a guest, your comment is unpublished.
    ERIC ARIAS · 2 years ago
    Can this VBA be modified to bold multiple texts, such as "KTE", "KTO", and "KTW"?
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, Eric,

      May be the following VBA code can help you to bold multiple specific cell, please apply the below code.
      Sub FindAndBold()
      Dim I As Long
      Dim xFind As String
      Dim xCell As Range
      Dim xTxtRg As Range
      Dim xCount As Long
      Dim xLen As Integer
      Dim xStart As Integer
      Dim xRg As Range, xRgFind As Range
      Dim xTxt As String
      Dim xArr() As String
      On Error Resume Next
      If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
      Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
      End If
      Set xRg = Application.InputBox("Please select data range:", "Kutools for Excel", xTxt, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      On Error Resume Next
      Set xTxtRg = Application.Intersect(xRg.SpecialCells(xlCellTypeConstants, xlTextValues), xRg)
      If xTxtRg Is Nothing Then
      MsgBox "There are no cells with text"
      Exit Sub
      End If
      Set xRgFind = Application.InputBox("Select the text cells you want to bold", "Kutools for Excel", , , , , , 8)
      If xRgFind Is Nothing Then
      MsgBox "No text was listed", vbInformation, "Kutools for Excel"
      Exit Sub
      End If
      ReDim xArr(xRgFind.Count - 1)
      For I = 0 To (xRgFind.Count - 1)
      xArr(I) = xRgFind(I + 1)
      Next
      For Each xCell In xTxtRg
      For I = 0 To UBound(xArr)
      xFind = Trim(xArr(I))
      xStart = InStr(xCell.Value, xFind)
      xLen = Len(xFind)
      Do While xStart > 0
      xCell.Characters(xStart, xLen).Font.Bold = True
      xCount = xCount + 1
      xStart = InStr(xStart + xLen, xCell.Value, xFind)
      Loop
      Next
      Next
      If xCount > 0 Then
      MsgBox "number of " & CStr(xCount) & " text be bolded!", vbInformation, "Kutools for Excel"
      Else
      MsgBox "Not find the specific text!", vbInformation, "Kutools for Excel"
      End If
      End Sub

      Hope it can help you, thank you!
      • To post as a guest, your comment is unpublished.
        Pedro Martins · 1 years ago
        Hello skyyang, can you help me out in my excel?
        If find "1º" in a cell with several lines, bold that cell line
      • To post as a guest, your comment is unpublished.
        ilie neagu · 1 years ago
        if I want to make bold the string G-AD only it doesn t work if i have in my cell G-AD and G-AD-bla-bla-bla (this G-AD should not be made BOLD)