Loncat ke daftar isi utama

Bagaimana cara menyalin hanya batas rentang yang dipilih di Excel?

Saat menggunakan Microsoft Excel, mudah untuk menyalin hanya nilai sel, pemformatan sel, rumus sel, dan sebagainya dari rentang dengan fungsi Tempel Spesial. Tapi pernahkah Anda mencoba menyalin hanya gaya batas dari rentang di Excel? Artikel ini akan menunjukkan kepada Anda metode menyalin hanya batas rentang yang dipilih ke rentang baru di Excel.

Salin hanya batas rentang yang dipilih dengan kode VBA


Salin hanya batas rentang yang dipilih dengan kode VBA

Kode VBA berikut bisa membantu Anda hanya menyalin gaya batas sel yang dipilih, lalu menerapkan gaya batas ini ke rentang baru di Excel. Silakan lakukan sebagai berikut.

1. tekan lain + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

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

Kode VBA: Salin hanya batas rentang yang dipilih di Excel

Sub CopyBorders()
'Updated by Extendoffice 20211203
    Dim xRg, yRg As Range
    On Error Resume Next
    
    Set xRg = Application.InputBox("Select Range with Borders to Copy...", "Kutools For Excel", , , , , , 8)
    Set yRg = Application.InputBox("Select Cell to Apply Borders to range..", "Kutools For Excel", , , , , , 8)
    
    
    With yRg.Borders(xlEdgeLeft)
        .LineStyle = xRg.Borders(xlEdgeLeft).LineStyle
        .ColorIndex = xRg.Borders(xlEdgeLeft).ColorIndex
        .TintAndShade = xRg.Borders(xlEdgeLeft).TintAndShade
        .Weight = xRg.Borders(xlEdgeLeft).Weight

    End With
    With yRg.Borders(xlEdgeTop)
        .LineStyle = xRg.Borders(xlEdgeTop).LineStyle
        .ColorIndex = xRg.Borders(xlEdgeTop).ColorIndex
        .TintAndShade = xRg.Borders(xlEdgeTop).TintAndShade
        .Weight = xRg.Borders(xlEdgeTop).Weight
    End With
    With yRg.Borders(xlEdgeBottom)
        .LineStyle = xRg.Borders(xlEdgeBottom).LineStyle
        .ColorIndex = xRg.Borders(xlEdgeBottom).ColorIndex
        .TintAndShade = xRg.Borders(xlEdgeBottom).TintAndShade
        .Weight = xRg.Borders(xlEdgeBottom).Weight
    End With
    With yRg.Borders(xlEdgeRight)
        .LineStyle = xRg.Borders(xlEdgeRight).LineStyle
        .ColorIndex = xRg.Borders(xlEdgeRight).ColorIndex
        .TintAndShade = xRg.Borders(xlEdgeRight).TintAndShade
        .Weight = xRg.Borders(xlEdgeRight).Weight
    End With

    With yRg.Borders(xlInsideHorizontal)
        .LineStyle = xRg.Borders(xlInsideHorizontal).LineStyle
        .ColorIndex = xRg.Borders(xlInsideHorizontal).ColorIndex
        .TintAndShade = xRg.Borders(xlInsideHorizontal).TintAndShade
        .Weight = xRg.Borders(xlInsideHorizontal).Weight
    End With
    With yRg.Borders(xlInsideVertical)
        .LineStyle = xRg.Borders(xlInsideVertical).LineStyle
        .ColorIndex = xRg.Borders(xlInsideVertical).ColorIndex
        .TintAndShade = xRg.Borders(xlInsideVertical).TintAndShade
        .Weight = xRg.Borders(xlInsideVertical).Weight
    End With
End Sub

3. tekan F5 kunci untuk menjalankan kode. Dalam bermunculan pertama Kutools untuk Excel kotak dialog, pilih rentang dengan batas yang perlu Anda salin, lalu klik OK .

4. Di kedua Kutools untuk Excel kotak dialog, pilih sel untuk menerapkan batas yang disalin, lalu klik OK tombol. Lihat tangkapan layar:

Kemudian Anda dapat melihat hanya gaya batas rentang yang dipilih yang disalin dan diterapkan ke rentang baru seperti gambar di bawah ini.


Terkait artikel:

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 (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hola me gusto mucho al macro para copiar los Bordes, pero al copiar los bordes me borra el formato que tienen las celtas es decir borra colores y otros formatos que ya tiene la celda. me puedes ayudar con una macro que me permita copiar los bordes de otra celta a otra sin borrar el formato que tiene la celda de destino?
This comment was minimized by the moderator on the site
Dobr媒 den,

D臎kuji za pomoc s kop铆rov谩n铆m pouze ohrani膷en铆.
艩lo by
D臎kuji.
Jirka
This comment was minimized by the moderator on the site
The code also copied my numeric formats and overwrote those in the target cells. Perhaps I did something wrong?
This comment was minimized by the moderator on the site
Hi David,
In my case, the code only copy the borders into the target cells. Can you tell me your Excel version? Thank you for your comment.
This comment was minimized by the moderator on the site
Hello crystal,
I know this is over a year later, but due to a rehosting of my e-mail system, your question rose to the top of my inbox.
My Excel version is 2016 16.0.4993.1001 as reported by Account>About
This comment was minimized by the moderator on the site
Hi David,
Glad to receive your reply. I have tested the code in my Excel 2016, but it still copy the border only. Do you mind sending a copy of your data to ? Sorry for the inconvenience.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations