Salt la conținutul principal

Cum să colorați sau să evidențiați anumite cuvinte din celule în Excel?

Dacă o celulă conține mai multe cuvinte, cum puteți evidenția un anumit cuvânt numai în această celulă? Și ce zici de evidențierea acestui anumit cuvânt în mai multe celule? Acest articol va oferi o metodă de realizare a acestuia.

Colorează anumite cuvinte dintr-o singură celulă / mai multe celule cu cod VBA


Colorează anumite cuvinte dintr-o singură celulă / mai multe celule cu cod VBA

Următorul cod VBA vă poate ajuta să evidențiați anumite cuvinte dintr-o selecție. Vă rugăm să faceți următoarele.

1. Selectați intervalul conține celulele pe care doriți să le evidențiați. Apoi apăsați tasta Alt + F11 tastele simultan pentru a deschide Microsoft Visual Basic pentru aplicații fereastră.

2. În deschidere Microsoft Visual Basic pentru aplicații fereastră, faceți clic pe Insera > Module. Apoi copiați și lipiți codul VBA în fereastra Cod.

Cod VBA: Colorează anumite cuvinte din celule în Excel

Sub HighlightStrings()
    Dim xHStr As String, xStrTmp As String
    Dim xHStrLen As Long, xCount As Long, I As Long
    Dim xCell As Range
    Dim xArr
    On Error Resume Next
    xHStr = Application.InputBox("What is the string to highlight:", "KuTools For Excel", , , , , , 2)
    If TypeName(xHStr) <> "String" Then Exit Sub
    Application.ScreenUpdating = False
        xHStrLen = Len(xHStr)
        For Each xCell In Selection
            xArr = Split(xCell.Value, xHStr)
            xCount = UBound(xArr)
            If xCount > 0 Then
                xStrTmp = ""
                For I = 0 To xCount - 1
                    xStrTmp = xStrTmp & xArr(I)
                    xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.ColorIndex = 3
                    xStrTmp = xStrTmp & xHStr
                Next
            End If
        Next
    Application.ScreenUpdating = True
End Sub

3. apasă pe F5 tasta pentru a rula codul. Și în Kutools pentru Excel caseta de dialog, introduceți cuvântul pe care îl veți evidenția în celule, apoi faceți clic pe OK buton. Vedeți captura de ecran:

Apoi, puteți vedea toate cuvintele pe care le-ați specificat sunt colorate în roșu în celulele selectate imediat, așa cum este prezentat mai jos.


Legate de articole:

Cele mai bune instrumente de productivitate de birou

🤖 Kutools AI Aide: Revoluționați analiza datelor pe baza: Execuție inteligentă   |  Generați codul  |  Creați formule personalizate  |  Analizați datele și generați diagrame  |  Invocați funcțiile Kutools...
Caracteristici populare: Găsiți, evidențiați sau identificați duplicatele   |  Ștergeți rândurile goale   |  Combinați coloane sau celule fără a pierde date   |   Rundă fără Formula ...
Super căutare: VLookup cu mai multe criterii    VLookup cu valori multiple  |   VLookup pe mai multe foi   |   Căutare fuzzy ....
Listă derulantă avansată: Creați rapid o listă derulantă   |  Listă drop-down dependentă   |  Listă derulantă cu selectare multiplă ....
Manager de coloane: Adăugați un număr specific de coloane  |  Mutați coloanele  |  Comutați starea vizibilității coloanelor ascunse  |  Comparați intervale și coloane ...
Caracteristici prezentate: Focus pe grilă   |  Vedere de proiectare   |   Big Formula Bar    Manager registru de lucru și foi   |  Biblioteca de resurse (Text automat)   |  Data Picker   |  Combinați foi de lucru   |  Criptare/Decriptare celule    Trimiteți e-mailuri după listă   |  Super Filtru   |   Filtru special (filtrează bold/italic/barat...) ...
Top 15 seturi de instrumente12 Text Instrumente (Adăuga text, Eliminați caractere,...)   |   50+ Diagramă Tipuri de (Gantt Chart,...)   |   40+ Practic Formule (Calculați vârsta pe baza zilei de naștere,...)   |   19 inserare Instrumente (Introduceți codul QR, Inserați imaginea din cale,...)   |   12 Convertire Instrumente (Numere la cuvinte, conversie valutara,...)   |   7 Merge & Split Instrumente (Rânduri combinate avansate, Celule divizate,...)   |   ... și altele

Îmbunătățiți-vă abilitățile Excel cu Kutools pentru Excel și experimentați eficiența ca niciodată. Kutools pentru Excel oferă peste 300 de funcții avansate pentru a crește productivitatea și a economisi timp.  Faceți clic aici pentru a obține funcția de care aveți cea mai mare nevoie...

Descriere


Fila Office aduce interfața cu file în Office și vă face munca mult mai ușoară

  • Activați editarea și citirea cu file în Word, Excel, PowerPoint, Publisher, Access, Visio și Project.
  • Deschideți și creați mai multe documente în filele noi ale aceleiași ferestre, mai degrabă decât în ​​ferestrele noi.
  • Vă crește productivitatea cu 50% și reduce sute de clicuri de mouse pentru dvs. în fiecare zi!
Comments (24)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Is there any chance that I can do both coloring and make words Bond with that VBA code? Please help me :)
This comment was minimized by the moderator on the site
Bonjour Cristal,
Merci pour ce code. Est-il possible de l'adapter pour mettre en évidence plusieurs mots "Apple,Rose,Vert,Merci"
Merci
This comment was minimized by the moderator on the site
Hi Cous,

The following VBA code can help. After running the code, you will get a dialog box. Please type in the words you want to highlight and separate them by comma.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/highlight.png
Sub HighlightStrings()
'Updated by Extendoffice 20230130
    Dim xHStr As String, xStrTmp As String
    Dim xHStrLen As Long, xCount As Long, I As Long
    Dim xCell As Range
    Dim xArr
    Dim xArr2
    On Error Resume Next
    xHStr = Application.InputBox("What is the string to highlight:", "KuTools For Excel", , , , , , 2)
    If TypeName(xHStr) <> "String" Then Exit Sub
    Application.ScreenUpdating = False
    
    xArr2 = Split(xHStr, ",")
    For j = 0 To UBound(xArr2)
        xHStr = xArr2(j)
    
        xHStrLen = Len(xHStr)
        For Each xCell In Selection
            xArr = Split(xCell.Value, xHStr)
            xCount = UBound(xArr)
            If xCount > 0 Then
                xStrTmp = ""
                For I = 0 To xCount - 1
                    xStrTmp = xStrTmp & xArr(I)
                    xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.ColorIndex = 3
                    xStrTmp = xStrTmp & xHStr
                Next
            End If
        Next
    Next
    
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Thank you. that was really helpful. Can someone please tell how to color the text instead of highlighting it?

Regards
This comment was minimized by the moderator on the site
Hi Shaik Faiaz hamad,

Excel does not allow coloring a part of a cell. I'm sorry I can't help you with this problem.
This comment was minimized by the moderator on the site
Thank you that is very useful. How can I Highlight a word instead of a font color?

Regards.
This comment was minimized by the moderator on the site
how could the script be altered to do the following?

increase the font by 1 size, and
highlight multiple words with one running of the script?

Thx!
This comment was minimized by the moderator on the site
Hi t.taln,

If you want to increae the font size by 1 and highlight multiple words at the same time, please add the following line after the line "xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.ColorIndex = 3" in the VBA code.
Note: You need to know the current font size of the selected cell beforehand, and then enter a number one size larger than the original word. The number 12 in the line below is the font size I will assign to the matching words. And the original font size of the word is 11.
xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.Size = 12
This comment was minimized by the moderator on the site
That's very nice, thx! I'm wondering if anyone knows how to make it work on Mac? Many thanks
Rated 5 out of 5
This comment was minimized by the moderator on the site
Ciao,
a me servirebbe evidenziare tutti i numeri (comprensivi di due decimali) da -10,00 a 0 in rosso e da 0 a +10,00 in verde. come posso fare per non aggiungere singolarmente ogni dato senza aggiungerli tutti manualmente?

Grazie mille
This comment was minimized by the moderator on the site
Hi Ciao,
Are your numbers located in different cells in a range? If so, you can create two conditional formatting rules (between -10 and 0, between 0 and 10) to highlight these numbers. If not, can you upload a screenshot of your data?
This comment was minimized by the moderator on the site
Buna,

Coloreaza cuvantul doar daca e la inceput. Daca e la mijloc in aceeasi casuta de excel sau la sfarsit nu-l coloreaza.
Ce anume as putea schimba in cod pentru a-l colora indiferent unde se afla in casuta excel?

Multumesc!
This comment was minimized by the moderator on the site
Hi Andreea,
If you only want to highlight the word if it is at the beginning of the selected cells. The following VBA code can do you a favor. Please give it a try.
Sub HighlightStrings()
'Updated by Extendoffice 20220805
    Dim xHStr As String, xStrTmp As String
    Dim xHStrLen As Long, xCount As Long, I As Long
    Dim xCell As Range
    Dim xArr
    On Error Resume Next
    xHStr = Application.InputBox("What is the string to highlight:", "KuTools For Excel", , , , , , 2)
    If TypeName(xHStr) <> "String" Then Exit Sub
    Application.ScreenUpdating = False
        xHStrLen = Len(xHStr)
        For Each xCell In Selection
            If xHStrLen <= Len(xCell.Value) Then
                If xHStr = Left(xCell.Value, xHStrLen) Then
                    xCell.Characters(1, xHStrLen).Font.ColorIndex = 3
                End If
            End If
        Next
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Bonjour,
Est-il possible de supprimer la boite de dialogue et de mettre par défaut "apple" comme mot recherché ?
Merci
This comment was minimized by the moderator on the site
Hello PAUC,
The following code can do you a favor. Please give it a try.
Sub HighlightStrings()
'Updated by Extendoffice 20220721
    Dim xHStr As String, xStrTmp As String
    Dim xHStrLen As Long, xCount As Long, I As Long
    Dim xCell As Range
    Dim xArr
    On Error Resume Next
    xHStr = "apple"
    If TypeName(xHStr) <> "String" Then Exit Sub
    Application.ScreenUpdating = False
        xHStrLen = Len(xHStr)
        For Each xCell In Selection
            xArr = Split(xCell.Value, xHStr)
            xCount = UBound(xArr)
            If xCount > 0 Then
                xStrTmp = ""
                For I = 0 To xCount - 1
                    xStrTmp = xStrTmp & xArr(I)
                    xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.ColorIndex = 3
                    xStrTmp = xStrTmp & xHStr
                Next
            End If
        Next
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Thanks... this was very helpful! Is there a way to adjust the macro so that it only highlights whole words instead of partials. For instance, I'm trying to highlight the word "design" but it highlights the "design" in the word "designate". I want it to skip over that word if it's not the whole word. Thanks!
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