Loncat ke daftar isi utama

Bagaimana cara menyisipkan spasi sebelum huruf kapital di excel?

Misalkan Anda memiliki daftar string teks yang semua spasi di antara kata-kata tersebut terhapus secara tidak sengaja, seperti ini: SisipkanBlankRowsAntaraData, dan sekarang Anda ingin menambahkan spasi sebelum setiap huruf dengan huruf kapital untuk memisahkan kata sebagai Sisipkan Baris Kosong Di Antara Data. Bagaimana Anda bisa menambahkan spasi di depan huruf besar dengan cepat alih-alih mengetik spasi satu per satu di Excel?


Sisipkan spasi sebelum huruf kapital dengan User Defined Function

Sayangnya, tidak ada cara langsung bagi Anda untuk menambahkan spasi sebelum huruf besar di Excel, tetapi Anda dapat membuat Fungsi Buatan Pengguna untuk menyelesaikan tugas ini.

1. Aktifkan lembar kerja Anda yang berisi string teks yang ingin Anda tambahkan spasi.

2. Tahan ALT + F11 kunci untuk membuka Jendela Microsoft Visual Basic for Applications.

3. Klik Menyisipkan > Modul, dan tempel kode berikut di Jendela modul.

Kode VBA: Sisipkan spasi sebelum huruf kapital

Function AddSpaces(pValue As String) As String
'Update 20140723
Dim xOut As String
xOut = VBA.Left(pValue, 1)
For i = 2 To VBA.Len(pValue)
   xAsc = VBA.Asc(VBA.Mid(pValue, i, 1))
   If xAsc >= 65 And xAsc <= 90 Then
      xOut = xOut & " " & VBA.Mid(pValue, i, 1)
   Else
      xOut = xOut & VBA.Mid(pValue, i, 1)
   End If
Next
AddSpaces = xOut
End Function

4. Kemudian simpan dan tutup kode ini, kembali ke lembar kerja, dan masukkan rumus ini = spasi tambahan (A1) ke dalam sel kosong selain data Anda, lihat tangkapan layar:
doc-tambahkan-spasi-sebelum-huruf besar-1

5. Dan kemudian seret gagang isian ke rentang yang Anda inginkan untuk memuat rumus ini, Anda akan mendapatkan spasi yang disisipkan sebelum setiap huruf kapital Anda.
doc-tambahkan-spasi-sebelum-huruf besar-1

Hapus spasi di depan / belakang / ekstra dengan mudah dalam sel

Kutools untuk Excel Hapus Spaces utilitas memungkinkan pengguna Excel untuk dengan mudah menghapus semua spasi utama, spasi tambahan, spasi ekstra, atau semua spasi dari sel yang dipilih dengan cepat.


iklan hapus spasi 1

Sisipkan spasi sebelum huruf kapital dengan kode VBA

Berikut adalah kode VBA lain yang dapat membantu Anda, lakukan hal berikut:

1. Tahan ALT + F11 kunci untuk membuka Jendela Microsoft Visual Basic for Applications.

2. Klik Menyisipkan > Modul, dan tempel kode berikut di Jendela modul.

Kode VBA: Sisipkan spasi sebelum huruf kapital

Sub AddSpacesRange()
'Update 20140723
Dim Rng As Range
Dim WorkRng As Range
Dim xOut As String
Dim xValue As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For Each Rng In WorkRng
    xValue = Rng.Value
    xOut = VBA.Left(xValue, 1)
    For i = 2 To VBA.Len(xValue)
       xAsc = VBA.Asc(VBA.Mid(xValue, i, 1))
       If xAsc >= 65 And xAsc <= 90 Then
          xOut = xOut & " " & VBA.Mid(xValue, i, 1)
       Else
          xOut = xOut & VBA.Mid(xValue, i, 1)
       End If
    Next
    Rng.Value = xOut
Next
Application.ScreenUpdating = True
End Sub

3. Lalu tekan F5 kunci untuk mengeksekusi kode ini, kotak prompt akan muncul untuk membiarkan Anda memilih rentang data yang ingin Anda gunakan.
doc-tambahkan-spasi-sebelum-huruf besar-1

4. Dan kemudian klik OK untuk menutup kotak prompt ini, spasi telah disisipkan sebelum huruf kapital sekaligus, lihat tangkapan layar:
doc-tambahkan-spasi-sebelum-huruf besar-1


Sisipkan spasi sebelum setiap huruf kapital dengan Kutools for Excel

Kutools untuk Excel Tambahkan Teks utilitas dapat membantu Anda melewati makro VBA dan menyisipkan spasi sebelum setiap huruf kapital dengan mudah di Excel.

Kutools untuk Excel - Dilengkapi dengan lebih dari 300 alat penting untuk Excel. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Unduh sekarang!

1. Pilih rentang di mana Anda akan menyisipkan spasi sebelum huruf kapital, dan klik Kutools > Teks > Tambahkan Teks. Lihat tangkapan layar:

2. Dalam kotak dialog Add Text pembuka, ketikkan spasi ke dalam Teks kotak, centang Hanya tambahkan ke opsi dan pilih Huruf pertama adalah huruf besar dari Hanya tambahkan ke daftar drop-down.

3. klik Ok tombol untuk menyisipkan spasi sebelum setiap huruf kapital seperti gambar layar berikut yang ditampilkan:
doc menambahkan spasi sebelum huruf besar 7

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now

Catatan: Metode ini juga akan menambahkan spasi di awal sel jika huruf pertama adalah kapital. Anda bisa melamar Kutools > Teks > Hapus Spaces untuk menghapus semua spasi utama dari sel yang dipilih.


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 (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This function handles two problems that the given solution doesn't cover:
1. non-English text (with diacritical marks)
2. successive capitals that should not have spaces after them

` Private Function AddSpaces(sText As String)As String
' Inserts a space immediately before a capital letter, except when successive characters are each capitalized.
' Last Updated: 2022-07-04
'
Dim sRet As String, i As Integer, sChar As String, bPrevWasUCase As Boolean

sRet = Left(sText, 1)
For i = 2 To Len(sText)
sChar = Mid(sText, i, 1)
If sChar = UCase(sChar) And Not bPrevWasUCase Then
sRet = sRet & " " & sChar
bPrevWasUCase = True
Else
sRet = sRet & sChar
bPrevWasUCase = False
End If
Next i

AddSpaces= sRet
End Function`
This comment was minimized by the moderator on the site
Hello friend,

Thanks for your share. I tried your VBA code, but it doesn't work. Our VBA code can handle the non-english text. I have test the french text and spaces are successfully inserted before the capital letters.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
Hello

First thanks a lot for your code example and the explanations. It works very well for my case.

I just have 1 Problem, some of the Strings contain words like URL, which should not be seperated.
Do you see a way to except for example "URL" from adding spaces?

Would be very nice if you can help. I tried already a while, but i dont know how to solve this..


Best regards
luca
This comment was minimized by the moderator on the site
hi wanna ask you if you found solution for you case, if you found solution please provide me with that
This comment was minimized by the moderator on the site
Hi,
Thanks for your comment and advice. I have sent your suggestion to the Kutools project team, I鈥檓 sure they鈥檒l improve it soon.
This comment was minimized by the moderator on the site
Found a solution?
This comment was minimized by the moderator on the site
Hi there, your code works fantastic. Do you know how to adapt code 20140723 to work on multiple sheets? I would like to add spaces between capital letters throughout the entire workbook. Thanks!
This comment was minimized by the moderator on the site
i need a help in excel i want to find Uppercase in a cell. for example: Sagar Paul MBA 16:04 i want MBA to be highlighted
This comment was minimized by the moderator on the site
I hope you can see it and give it a trial. Sub Test() Dim Rg As Range, xCell As Range Dim i As Long Dim xChar As String Set Rg = Application.Selection For Each xCell In Rg For i = 1 To xCell.Characters.Count xChar = xCell.Characters(i, 1).Text If Asc(xChar) > 64 And Asc(xChar) < 91 Then xCell.Characters(i, 1).Font.Color = vbRed End If Next Next End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations