Loncat ke daftar isi utama

Bagaimana cara menebalkan hanya baris pertama atau kata pertama dalam sel di Excel?

Dalam lembar kerja Excel, mungkin ada banyak sel yang berisi beberapa baris yang diberi paragraf dengan tombol Alt + Enter. Dalam beberapa kasus, Anda mungkin hanya perlu menebalkan baris pertama di sel ini. Atau hanya cetak tebal kata pertama untuk membuatnya menonjol dalam sel. Artikel ini menunjukkan dua metode bagi Anda untuk mencapainya secara detail.

Cetak tebal hanya baris pertama dalam sel dengan kode VBA Cetak tebal hanya kata pertama dalam sel dengan kode VBA


Cetak tebal hanya baris pertama dalam sel dengan kode VBA

Kode VBA berikut dapat membantu Anda dengan cepat mencetak tebal hanya baris pertama di sel yang dipilih. Silakan lakukan sebagai berikut.

1. tekan lain + F11 tombol secara bersamaan untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Dalam Microsoft Visual Basic untuk Aplikasi window, klik Menyisipkan > Modul. Kemudian salin dan tempel kode VBA di bawah ini ke jendela Modul.

Kode VBA: Cetak tebal hanya baris pertama dalam sel

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. tekan F5 kunci untuk menjalankan kode. Kemudian a Kutools untuk Excel kotak dialog muncul, pilih rentang dengan baris pertama yang Anda butuhkan untuk membuatnya tebal, lalu klik OK .

Kemudian Anda dapat melihat semua baris pertama dari sel yang dipilih segera dicetak tebal seperti gambar di bawah ini.


Cetak tebal hanya kata pertama dalam sel dengan kode VBA

Seperti gambar di bawah ini yang ditunjukkan, terkadang, Anda perlu menebalkan kata pertama hanya dalam rentang A2: A4 di Excel. Anda dapat mencapainya sebagai berikut selangkah demi selangkah.

1. tekan lain + F11 tombol secara bersamaan untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Dalam Microsoft Visual Basic untuk Aplikasi window, klik Menyisipkan > Modul. Kemudian salin dan tempel kode VBA di bawah ini ke jendela Modul.

Kode VBA: Cetak tebal hanya kata pertama dalam sel

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. tekan F5 kunci untuk menjalankan kode. Dalam bermunculan Kutools untuk Excel kotak dialog, pilih rentang yang Anda inginkan untuk membuat kata pertama tebal, lalu tekan OK tombol. Lihat tangkapan layar:

Kemudian Anda dapat melihat semua kata pertama dari sel yang dipilih segera dicetak tebal seperti gambar di bawah ini.


Artikel terkait:

Alat Produktivitas Kantor Terbaik

🤖 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
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