Note: The other languages of the website are Google-translated. Back to English
Masuk  \/ 
x
or
x
Daftar  \/ 
x

or

Bagaimana cara mempertahankan garis kisi sambil mengisi warna di Excel?

Seperti yang kita semua ketahui, ketika kita mengisi warna latar belakang ke sel, garis kisi akan tercakup juga, dalam hal ini, bagaimana kita bisa mempertahankan garis kisi sambil mengisi warna latar belakang di sel Excel untuk menampilkan tangkapan layar berikut.

doc menjaga garis kisi mengisi warna 1

Pertahankan garis kisi sambil mengisi warna dengan kode VBA


panah gelembung kanan biru Pertahankan garis kisi sambil mengisi warna dengan kode VBA


Biasanya, tidak ada cara langsung bagi kami untuk menyelesaikan pekerjaan ini, tetapi, di sini, saya dapat memperkenalkan kode VBA untuk Anda. Harap lakukan sebagai berikut:

1. Tahan ALT + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Di kiri Proyek-VBAProject panel, klik dua kali Buku Kerja Ini di bawah diperluas VBAProject, lalu salin dan tempel kode VBA berikut ke dalam Modul kosong:

Kode VBA: pertahankan garis kisi sambil mengisi warna

Dim xRgPre As Range
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If Not xRgPre Is Nothing Then DrawBorders xRgPre
    Set xRgPre = Target
End Sub
Private Sub DrawBorders(ByVal Rg As Range)
'Updateby Extendoffice 20160725
    Dim xCell As Range
    Application.ScreenUpdating = False
    For Each xCell In Rg
        If xCell.Interior.ColorIndex = xlNone Then
            With xCell.Borders
                If .ColorIndex = 15 Then
                    .LineStyle = xlNone
                End If
            End With
        Else
            With xCell.Borders
                If .LineStyle = xlNone Then
                    .Weight = xlThin
                    .ColorIndex = 15
                End If
            End With
        End If
    Next
    Application.ScreenUpdating = True
End Sub

doc menjaga garis kisi mengisi warna 2

3. Dan kemudian simpan dan tutup jendela kode, sekarang, saat Anda mengisi warna untuk rentang sel, garis kisi akan ditampilkan secara otomatis.


Alat Produktivitas Kantor Terbaik

Kutools for Excel Memecahkan Sebagian Besar Masalah Anda, dan Meningkatkan Produktivitas Anda hingga 80%

  • Reuse: Masukkan dengan cepat rumus, bagan yang kompleks dan apa pun yang pernah Anda gunakan sebelumnya; Enkripsi Sel dengan kata sandi; Buat Milis dan mengirim email ...
  • Super Formula Bar (dengan mudah mengedit beberapa baris teks dan rumus); Membaca Tata Letak (membaca dan mengedit sel dalam jumlah besar dengan mudah); Tempel ke Rentang yang Difilter...
  • Gabungkan Sel / Baris / Kolom tanpa kehilangan Data; Pisahkan Konten Sel; Gabungkan Baris / Kolom Duplikat... Mencegah Sel Duplikat; Bandingkan Rentang...
  • Pilih Duplikat atau Unik Baris; Pilih Baris Kosong (semua sel kosong); Temukan Super dan Temukan Fuzzy di Banyak Buku Kerja; Pilih Acak ...
  • Salinan Tepat Beberapa Sel tanpa mengubah referensi rumus; Buat Referensi Otomatis ke Beberapa Lembar; Sisipkan Poin, Kotak Centang, dan lainnya ...
  • Ekstrak Teks, Tambahkan Teks, Hapus berdasarkan Posisi, Hapus Space; Membuat dan Mencetak Subtotal Paging; Konversi Konten Antar Sel dan Komentar...
  • Filter Super (simpan dan terapkan skema filter ke sheet lain); Penyortiran Lanjutan menurut bulan / minggu / hari, frekuensi dan lainnya; Filter Khusus dengan huruf tebal, miring ...
  • Gabungkan Workbooks dan WorkSheets; Gabungkan Tabel berdasarkan kolom kunci; Pisahkan Data menjadi Beberapa Lembar; Konversi Batch xls, xlsx dan PDF...
  • Lebih dari 300 fitur canggih. Mendukung Office / Excel 2007-2019 dan 365. Mendukung semua bahasa. Penerapan yang mudah di perusahaan atau organisasi Anda. Fitur lengkap uji coba gratis 30 hari. Jaminan uang kembali 60 hari.
kte tab 201905

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.
  • Tingkatkan produktivitas Anda hingga 50%, dan kurangi ratusan klik mouse untuk Anda setiap hari!
officetab bawah
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Jose · 2 months ago
    Great was trying to paind for a good loook of my site presentation https://jpeeiclinic.blogspot.com
  • To post as a guest, your comment is unpublished.
    JL · 6 months ago
    @Alissa This helped me SO much. I have literally been searching so many places and this is the only explanation that worked! Thank you!!!
  • To post as a guest, your comment is unpublished.
    Fox · 11 months ago
    @Alissa Alissa , I had the same problem couldn`t get it fixed but your reply helped me a lot , so thank you very much , you are genius .
  • To post as a guest, your comment is unpublished.
    Chad · 1 years ago
    Thank you! I was pulling hairs trying to get the nice grey-ish borders to stay after colorizing. Can't believe Microsoft hasn't already implemented this.
  • To post as a guest, your comment is unpublished.
    James Godesky · 1 years ago
    @Terry Does not work with Conditional Formatting. Set xRqPre = Nothing gives error: variable not defined (deleted the line).Screen jiggles here too, using 2010. Other wise its a cool tool..
  • To post as a guest, your comment is unpublished.
    Armaan Sandhu · 1 years ago
    @Alissa Thank you!!
  • To post as a guest, your comment is unpublished.
    jdjshark@gmail.com · 1 years ago
    @Vic Same here with Excel 2016. I'm getting freezing and mostly blanked out screen for several seconds, especially when selecting many cells. It's a shame because it does work perfectly otherwise.
  • To post as a guest, your comment is unpublished.
    Alissa · 2 years ago
    Another fix, if you don't want to mess with code:
    First figure out which color gray matches the default lines and have it in mind.
    In the Home tab click Cell styles, right click on Normal, click Modify -> Format -> Border. For Line Color, select that gray. For Presets, select Outline. Done.
    Now you may have to select all (CTRL+A / Command+A) and click Cell styles -> Normal to make sure it's applied to all cells. When you fill a cell, the borders will remain.
  • To post as a guest, your comment is unpublished.
    skyyang · 3 years ago
    @Andrew Hello, Andrew,
    Yes, the above code can not support Undo feature, you should fill no color manually to undo your work.
    Thank you!
  • To post as a guest, your comment is unpublished.
    Andrew · 3 years ago
    Cool, but now if I fill some cells, and hit Ctrl+Z to undo, it won't work. Will not undo.
  • To post as a guest, your comment is unpublished.
    barbatus · 3 years ago
    use only standard colors ;)
  • To post as a guest, your comment is unpublished.
    Terry · 3 years ago
    works but one has to correct the error if you see it.
    Dim xRgPre As Range
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If Not xRgPre Is Nothing Then DrawBorders xRgPre
    Set xRgPre = Target


    *************************************
    Should READ... as the If statement only ensures that something is there to set to memory allocation.

    One could set the next line below for clean up and not allow memory leaks.

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    Set xRgPre = Target
    If Not xRgPre Is Nothing Then DrawBorders xRgPre
    'For ensured memory leaks do not happen
    'Clean up the memory allocated after it is not needed.
    Set xRqPre = Nothing



    Have a nice day..
  • To post as a guest, your comment is unpublished.
    skyyang · 3 years ago
    @Vic Hi, Vic,
    There is no this problem in my Excel workbook, which Excel version do you use?
  • To post as a guest, your comment is unpublished.
    Vic · 3 years ago
    Works fine, but sadly every time I now click on a cell, the worksheet judders! Removed the VBA and the judder has ceased. Wonder why this should happen?
  • To post as a guest, your comment is unpublished.
    dolphinks · 3 years ago
    Fabulous fix!!