Vai al contenuto principale

Come mettere in grassetto solo la prima riga o la prima parola nella cella in Excel?

In un foglio di lavoro Excel, potrebbero esserci molte celle contenenti più righe che sono state divise con i tasti Alt + Invio. In alcuni casi, potrebbe essere necessario mettere in grassetto solo la prima riga di queste celle. O solo in grassetto la prima parola per renderlo eccezionale nelle celle. Questo articolo mostra due metodi per ottenerlo nei dettagli.

Grassetto solo la prima riga nella cella con codice VBA Grassetto solo la prima parola nella cella con codice VBA


Grassetto solo la prima riga nella cella con codice VBA

Il seguente codice VBA può aiutarti a mettere rapidamente in grassetto solo la prima riga nelle celle selezionate. Si prega di fare quanto segue.

1. Stampa altro + F11 tasti contemporaneamente per aprire il file Microsoft Visual Basic, Applications Edition finestra.

2. Nel Microsoft Visual Basic, Applications Edition finestra, fare clic inserire > Moduli. Quindi copia e incolla il codice VBA sottostante nella finestra del modulo.

Codice VBA: grassetto solo la prima riga nelle celle

Option Explicit
Sub BoldFirstLine()
Dim xRng As Range, xCell As Range
Dim xFirstRow As String
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools for", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
On Error Resume Next
For Each xCell In xRng
    With xCell
        .Characters(1, InStr(.Value, Chr(10))).Font.Bold = True
    End With
Next
End Sub

3. premi il F5 chiave per eseguire il codice. Poi un Kutools for Excel si apre la finestra di dialogo, selezionare l'intervallo con la prima riga necessaria per renderlo in grassetto, quindi fare clic su OK pulsante.

Quindi puoi vedere tutte le prime righe delle celle selezionate in grassetto immediatamente come mostrato nell'immagine sottostante.


Grassetto solo la prima parola nella cella con codice VBA

Come mostrato nell'immagine sottostante, a volte è necessario mettere in grassetto la prima parola solo nell'intervallo A2: A4 in Excel. Puoi ottenerlo come segue passo dopo passo.

1. Stampa altro + F11 tasti contemporaneamente per aprire il file Microsoft Visual Basic, Applications Edition finestra.

2. Nel Microsoft Visual Basic, Applications Edition finestra, fare clic inserire > Moduli. Quindi copia e incolla il codice VBA sottostante nella finestra del modulo.

Codice VBA: in grassetto solo la prima parola nelle celle

Sub boldtext()
Dim xRng As Range, xCell As Range
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools fro Excel", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
On Error Resume Next
For Each xCell In xRng
  If xCell.Value <> "" Then
    xCell.Characters(1, InStr(1, xCell.Value, " ") - 1).Font.Bold = True
  End If
Next
End Sub

3. premi il F5 chiave per eseguire il codice. Nel spuntare Kutools for Excel finestra di dialogo, selezionare l'intervallo in cui si desidera rendere la prima parola in grassetto, quindi premere il tasto OK pulsante. Vedi screenshot:

Quindi puoi vedere tutte le prime parole delle celle selezionate in grassetto immediatamente come mostrato nell'immagine sottostante.


Articolo correlato:

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
Comments (11)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Thank you! Works perfect.
This comment was minimized by the moderator on the site
Hello,

How to bold only the Last line of the cell?
This comment was minimized by the moderator on the site
Hi Spulber,
The following VBA code can help you bold only the last line of each cell in the selected range.
Please note that if a cell has only one line (i.e., no line breaks), then the entire cell content will be bolded. If a cell is empty or contains only numerical values, this subroutine will not affect it.

Option Explicit
'Updated by Extendoffice 20230721
Sub BoldLastLine()
    Dim xRng As Range, xCell As Range
    Dim xLastLineStart As Long
    Dim xTextLength As Long
    
    On Error Resume Next
    Set xRng = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8)
    
    If xRng Is Nothing Then Exit Sub
    On Error GoTo 0
    
    For Each xCell In xRng
        With xCell
            xTextLength = Len(.Value)
            xLastLineStart = InStrRev(.Value, Chr(10)) + 1
            If xLastLineStart > xTextLength Then xLastLineStart = 1
            .Characters(xLastLineStart, xTextLength).Font.Bold = True
        End With
    Next
End Sub
This comment was minimized by the moderator on the site
This is fantastic, thanks so much!
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi. I have many cells that contain multiple lines which were paragraphed by Alt+Enter. I would like to bold and change the color of the first word of each line. Can you help please?
This comment was minimized by the moderator on the site
Hi I have quite a few lines in a cell . I want for make 5th line as bold and italics in a cell . The below code makes only the first line . Can you help

Sub bold()


Dim r As Range, c As Range
Dim ws As Worksheet

Set ws = ActiveSheet
Set r = ws.Range("Y:Y")
For Each c In r
With c
.Font.bold = False
.Value = .Text
.Characters(1, InStr(.Text, vbLf) - 1).Font.bold = True
End With

Next c


End Sub
This comment was minimized by the moderator on the site
How about if I want the second line to be bold?
This comment was minimized by the moderator on the site
Good Day!
If you want to bold only the second line of the cell, please try the following VBA code:

Sub BoldSecondLine()
Dim xRng As Range, xCell As Range
Dim xArr
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools for", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
For Each xCell In xRng
If xCell <> "" Then
With xCell
xArr = Split(xCell, Chr(10))
.Characters(InStr(.Value, Chr(10)) + 1, Len(xArr(1))).Font.Bold = True
End With
End If
Next
End Sub
This comment was minimized by the moderator on the site
Hi, How about if I want the first three words to be bold?
This comment was minimized by the moderator on the site
Good Day,
Please try below VBA script.

Sub boldtext()
Dim xRng As Range, xCell As Range
Dim xNum As Long, xCount As Long
Dim I As Long, J As Long
Dim xArr
Dim xArrChr10
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools fro Excel", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
For Each xCell In xRng
xNum = 0
xCount = 0
xArrChr10 = Split(xCell.Value, Chr(10))
For I = 0 To UBound(xArrChr10)
xArr = Split(xArrChr10(I))
For J = 0 To UBound(xArr)
If xArr(J) <> "" Then
xCount = xCount + 1
If xCount > 3 Then Exit For
End If
xNum = xNum + Len(xArr(J)) + 1
Next
Next
xCell.Characters(1, xNum).Font.Bold = True
Next
End Sub
This comment was minimized by the moderator on the site
HI, how about if i want the first two lines to be bold?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations