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

or

Bagaimana cara mengubah warna sel saat sel diklik atau dipilih di Excel?

Artikel ini akan menunjukkan kepada Anda beberapa metode tentang cara mengubah warna sel saat mengklik sel, dan mengubah warna yang disorot saat memilih rentang sel di Excel.

Ubah warna sel saat sel diklik dengan kode VBA
Ubah warna yang disorot saat sel dipilih dengan kode VBA
Sorot seluruh baris dan kolom sel aktif dengan Kutools for Excel


Ubah warna sel saat sel diklik dengan kode VBA

Di sini, Anda dapat mengubah warna latar belakang sel saat mengklik dua kali atau mengklik kanan sel dengan kode VBA berikut.

1. Pada lembar kerja Anda akan mengubah warna sel saat mengkliknya, klik kanan tab lembar dan klik Lihat kode dari menu klik kanan.

2. Dalam Microsoft Visual Basic untuk Aplikasi jendela, silakan salin dan tempel kode VBA di bawah ini ke Kode jendela.

VBA: ubah warna sel saat mengkliknya

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbRed
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbGreen
End Sub

3. tekan lain + Q tombol secara bersamaan untuk menutup Microsoft Visual Basic untuk Aplikasi jendela.

Kemudian, saat Anda mengklik dua kali sel, itu akan diwarnai dengan warna merah. Dan saat Anda mengklik kanan pada sel, itu akan diwarnai dengan warna hijau. Lihat tangkapan layar:


Satu klik untuk menyorot baris dan kolom sel yang dipilih di Excel:

Kutools untuk Excel's Membaca Tata Letak utilitas membantu Anda dengan cepat menyorot baris dan kolom sel yang dipilih di Excel seperti yang ditunjukkan demo di bawah ini.
Unduh dan coba sekarang! (Jejak gratis 30 hari)


Ubah warna yang disorot saat sel dipilih dengan kode VBA

Secara default, saat memilih rentang sel, warna yang disorot berwarna abu-abu. Jika Anda ingin membuat rentang yang dipilih lebih menonjol, Anda dapat mengubah warna yang disorot menjadi yang Anda butuhkan. Silakan lakukan sebagai berikut.

1. Klik kanan tab lembar yang ingin Anda ubah warna yang disorot dari rentang yang dipilih, dan klik Lihat kode dari menu klik kanan.

2. Dalam Microsoft Visual Basic untuk Aplikasi jendela, silakan salin dan tempel kode VBA di bawah ini ke Kode jendela.

Kode VBA: ubah warna yang disorot dari rentang yang dipilih

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
        .Worksheet.Cells.FormatConditions.Delete
        .FormatConditions.Add xlExpression, , "TRUE"
        .FormatConditions(1).Interior.Color = vbYellow
    End With
End Sub

3. tekan lain + Q kunci sekaligus untuk menutup Microsoft Visual Basic untuk Aplikasi jendela.

Mulai sekarang, warna yang disorot dari rentang atau sel yang dipilih diubah menjadi kuning. Saat Anda mengklik sel atau rentang sel lain, sel akan diwarnai secara otomatis.


Sorot seluruh baris dan kolom sel aktif dengan Kutools for Excel

Jika Anda berurusan dengan lembar kerja yang besar, Anda perlu menyorot seluruh baris dan kolom sel aktif agar pembacaan lebih mudah. Di sini Membaca Tata Letak kegunaan Kutools untuk Excel bisa membantumu.

Sebelum melamar Kutools untuk Excel, Mohon unduh dan instal terlebih dahulu.

1. klik Kutools > Membaca Tata Letak. Lihat tangkapan layar:

Kemudian tata letak membaca diaktifkan, Anda dapat melihat baris dan kolom sel aktif segera disorot.

Catatan: Anda dapat mengubah pengaturan tata letak bacaan berdasarkan kebutuhan Anda seperti gambar di bawah ini.

  Jika Anda ingin memiliki uji coba gratis (30 hari) dari utilitas ini, silahkan klik untuk mendownloadnya, lalu lanjutkan untuk menerapkan operasi sesuai langkah di atas.


Sorot seluruh baris dan kolom sel aktif dengan Kutools for Excel


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.
tab kte 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.
    Vera · 11 months ago
    Hi,
    is it possible to have a code for "change cell color when clicking on it" in the way that it will not change already formated cells with another color, please?
    After applying your code all my formating (colours) is away. Thank you. Veronika
  • To post as a guest, your comment is unpublished.
    kiba fil · 1 years ago
    Thank you. Great Job
  • To post as a guest, your comment is unpublished.
    shea honig · 1 years ago
    hi
    the is working grate but i want that the color should only be when the cell is selected and when i select something else, the first cell i selcted should not be colored
    can you help me pls with this thanks
    • To post as a guest, your comment is unpublished.
      Kris · 1 years ago
      I had that exact same question! I hope someone will answer you! The reason I am looking for this is I have a spreadsheet I use daily and put in lots of information into single cells. It gets hard to see the values (visually, it runs into info in other cells), and would be a great feature if I could change the color of the cell being edited - only while it is being edited. The simplest solution I can think of is that the cell value would be set back to what it was prior to being clicked on - but I don't know how to do that.
  • To post as a guest, your comment is unpublished.
    perry · 1 years ago
    Hi, I am trying to figure out how to change the color of a cell, based on a selection from a dropdown list. For example, HIGH=red, MEDIUM=yellow, LOW=green.

    Any tips you can provide are greatly appreciated. Thank You
  • To post as a guest, your comment is unpublished.
    Vishnu Subind · 2 years ago
    Hi guys, so i used to first code to change the cell colour to green/red on doubleclick/rightclick. I would like this code, however, to work just on a specific range of cells, in my case D9:P9. can someone help me on how to do that? Im new at VBA
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      The below VBA code can do you a favor, please have a try. Thank you for your comment.

      Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      If (Not Application.Intersect(Target, Me.Range("D9:P9")) Is Nothing) Then
      Cancel = True
      Target.Interior.Color = vbRed
      End If
      End Sub
      Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
      If (Not Application.Intersect(Target, Me.Range("D9:P9")) Is Nothing) Then
      Cancel = True
      Target.Interior.Color = vbGreen
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    rahayu · 2 years ago
    trimakasih
  • To post as a guest, your comment is unpublished.
    rahayu · 2 years ago
    td muncul=tidak muncul
  • To post as a guest, your comment is unpublished.
    rahayu · 2 years ago
    Salam...
    sy sudah install kutools, tp kok td muncul tab kutools di layar excel ya? gmn cara mmunculkannya?trimakasih
  • To post as a guest, your comment is unpublished.
    vuongngocsangbkdn@gmail.com · 2 years ago
    I have a problem.
    I want change color of one hyperlink if it had linked with one PDF to RED and if had not link with one PDF will show BLUE color.
    How can I do now?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good day,
      Sorry can't help you with that. Thanks for commenting.
  • To post as a guest, your comment is unpublished.
    devika.kalika@gmail.com · 2 years ago
    I tried the "Change the highlighted color when cells are selected with VBA code" option and saved my excel as Macro Enabled Worksheet. Now the last cells that were selected are highlighted and won't highlight other cells when selected. I've deleted code and reentered and saved, but still no change. I can't remove the previous highlight either. I'm at lost on what to do.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi,
      The code works well in my case after saving the workbook as an Excel Macro-Enabled Workbook.
      Can you tell me your Excel version?
  • To post as a guest, your comment is unpublished.
    Jason · 2 years ago
    Is there a way to just apply this to certain cells while leaving other cells with available for number entering?
  • To post as a guest, your comment is unpublished.
    Slaxx · 2 years ago
    hi. just a little heads up. i'm using office 2007.
    i tried your code, and while it did work, it wasn't what i was looking for. so i just deleted the code completely. but the last selected/active cell before i deleted the code is still green (i changed the color from vbYellow to vbGreen), and the color won't go away. it's not affected by fill color either.
    the simplest solution i found was to just delete the cell. copying and pasting will not work, it will also copy the color.
    just thought i'd let you know. you might find another solution/troubleshooting for this, besides deleting and manual entry. still, thanks! i confirm that the code works :)
  • To post as a guest, your comment is unpublished.
    Michelle · 3 years ago
    I love how easy formatting my worksheet the code for "change cell color when clicking on it" would make my daily work! I am hitting a snag though. When I copy my Blank Sheet with the code entered as described, I get a error. It runs great until I create new sheets. I am a novice at coding and am working from textbooks and the internet. I appreciate any help you will offer!
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Michelle,
      I followed the steps as you described, but the code also worked in my case. Can you tell me your Office version?
      Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    madhav neupane · 3 years ago
    thank you thank you so much. I appreciate you for this.