Saltar al contenido principal

¿Cómo poner en negrita solo la primera línea o la primera palabra en la celda en Excel?

En una hoja de cálculo de Excel, puede haber muchas celdas que contengan varias líneas que fueron paragrafiadas por las teclas Alt + Enter. En algunos casos, es posible que deba poner en negrita solo la primera línea en estas celdas. O solo en negrita la primera palabra para resaltarla en las celdas. Este artículo muestra dos métodos para lograrlo en detalle.

Negrita solo la primera línea en la celda con código VBA Negrita solo la primera palabra en la celda con código VBA


Negrita solo la primera línea en la celda con código VBA

El siguiente código VBA puede ayudarlo a poner en negrita rápidamente solo la primera línea en las celdas seleccionadas. Haz lo siguiente.

1. Prensa otro + F11 teclas simultáneamente para abrir el Microsoft Visual Basic para aplicaciones ventana.

2. En el Microsoft Visual Basic para aplicaciones ventana, haga clic recuadro > Módulo. Luego copie y pegue el siguiente código VBA en la ventana del Módulo.

Código de VBA: negrita solo la primera línea en las celdas

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. presione el F5 clave para ejecutar el código. Entonces un Kutools for Excel aparece el cuadro de diálogo, seleccione el rango con la primera línea que necesita para ponerla en negrita, y luego haga clic en el OK del botón.

Luego, puede ver que todas las primeras líneas de las celdas seleccionadas están en negrita inmediatamente, como se muestra a continuación.


Negrita solo la primera palabra en la celda con código VBA

Como se muestra a continuación en la captura de pantalla, a veces, debe poner en negrita la primera palabra solo en el rango A2: A4 en Excel. Puede lograrlo de la siguiente manera paso a paso.

1. Prensa otro + F11 teclas simultáneamente para abrir el Microsoft Visual Basic para aplicaciones ventana.

2. En el Microsoft Visual Basic para aplicaciones ventana, haga clic recuadro > Módulo. Luego copie y pegue el siguiente código VBA en la ventana del Módulo.

Código de VBA: negrita solo la primera palabra en las celdas

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. presione el F5 clave para ejecutar el código. En el apareciendo Kutools for Excel cuadro de diálogo, seleccione el rango en el que desea poner la primera palabra en negrita, y luego presione el OK botón. Ver captura de pantalla:

Luego, puede ver que todas las primeras palabras de las celdas seleccionadas están en negrita inmediatamente, como se muestra a continuación.


Artículo relacionado:

Las mejores herramientas de productividad de oficina

🤖 Asistente de IA de Kutools: Revolucionar el análisis de datos basado en: Ejecución inteligente   |  Generar codigo  |  Crear fórmulas personalizadas  |  Analizar datos y generar gráficos  |  Invocar funciones de Kutools...
Características populares: Buscar, resaltar o identificar duplicados   |  Eliminar filas en blanco   |  Combine columnas o celdas sin perder datos   |   Ronda sin fórmula ...
Super búsqueda: Búsqueda virtual de criterios múltiples    Búsqueda V de valores múltiples  |   VLookup en varias hojas   |   Búsqueda difusa ....
Lista desplegable avanzada: Crear rápidamente una lista desplegable   |  Lista desplegable dependiente   |  Lista desplegable de selección múltiple ....
Administrador de columnas: Agregar un número específico de columnas  |  Mover columnas  |  Toggle Estado de visibilidad de columnas ocultas  |  Comparar rangos y columnas ...
Características destacadas: Enfoque de cuadrícula   |  Vista de diseño   |   Gran barra de fórmulas    Administrador de hojas y libros de trabajo   |  Biblioteca de Recursos (Texto automático)   |  Selector de fechas   |  Combinar hojas de trabajo   |  Cifrar/descifrar celdas    Enviar correos electrónicos por lista   |  Súper filtro   |   Filtro especial (filtro negrita/cursiva/tachado...) ...
Los 15 mejores conjuntos de herramientas12 Texto Herramientas (Añadir texto, Quitar caracteres, ...)   |   50+ Tabla Tipos (Diagrama de Gantt, ...)   |   40+ Práctico Fórmulas (Calcular la edad según el cumpleaños, ...)   |   19 Inserción Herramientas (Insertar código QR, Insertar imagen desde la ruta, ...)   |   12 Conversión Herramientas (Números a palabras, Conversión de Moneda, ...)   |   7 Fusionar y dividir Herramientas (Filas combinadas avanzadas, Células partidas, ...)   |   ... y más

Mejore sus habilidades de Excel con Kutools for Excel y experimente la eficiencia como nunca antes. Kutools for Excel ofrece más de 300 funciones avanzadas para aumentar la productividad y ahorrar tiempo.  Haga clic aquí para obtener la función que más necesita...

Descripción


Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilite la edición y lectura con pestañas en Word, Excel, PowerPoint, Publisher, Access, Visio y Project.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta su productividad en un 50% y reduce cientos de clics del mouse todos los días!
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