Loncat ke daftar isi utama

Bagaimana cara menyorot sel atau seleksi aktif di Excel?

Jika Anda memiliki lembar kerja yang besar, mungkin sulit bagi Anda untuk mengetahui sel aktif atau pilihan aktif secara sekilas. Namun, jika sel / bagian yang aktif memiliki warna yang menonjol, untuk mengetahuinya tidak akan menjadi masalah. Pada artikel ini, saya akan berbicara tentang cara menyorot sel aktif atau rentang sel yang dipilih secara otomatis di Excel.

Sorot sel aktif atau seleksi dengan kode VBA


panah gelembung kanan biru Sorot sel aktif atau seleksi dengan kode VBA

Kode VBA berikut dapat membantu Anda menyorot sel aktif atau pilihan secara dinamis, lakukan hal berikut:

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

2. Lalu pilih Buku Kerja Ini dari kiri Penjelajah Proyek, klik dua kali untuk membuka file Modul, lalu salin dan tempel kode VBA berikut ke dalam modul kosong:

Kode VBA: Sorot sel aktif atau pilihan

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
'Update 20140923
Static xLastRng As Range
On Error Resume Next
Target.Interior.ColorIndex = 6
xLastRng.Interior.ColorIndex = xlColorIndexNone
Set xLastRng = Target
End Sub

doc-sorot-aktif-sel-1

3. Kemudian simpan dan tutup kode ini, dan kembali ke lembar kerja, sekarang, saat Anda memilih sel atau pilihan, sel yang dipilih akan disorot, dan itu akan dipindahkan secara dinamis saat sel yang dipilih berubah.

Catatan:

1. Jika Anda tidak dapat menemukan file Panel Penjelajah Proyek di jendela, Anda dapat mengklik View > Penjelajah Proyek dalam Jendela Microsoft Visual Basic for Applications untuk membukanya

2. Pada kode di atas, Anda dapat mengubahnya .Indeks Warna = 6 warna ke warna lain yang Anda suka.

3. Kode VBA ini dapat diterapkan ke semua lembar kerja di dalam buku kerja.

4. Jika ada beberapa sel berwarna di lembar kerja Anda, warna tersebut akan hilang saat Anda mengklik sel dan kemudian pindah ke sel lain.


Artikel terkait:

Bagaimana cara menyorot otomatis baris dan kolom sel aktif di Excel?

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 (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I had the same problem, read the whole page and comments. While thinking to apply it or not, I was just randomly clicking on number and letters to select the whole column and rows. Then suddenly highlight of selected cell feature came back :)
This comment was minimized by the moderator on the site
Hello, if someone can help me... I pick up this code in internet (apologies to the owner). It does almost what i need but this code select the entirerow. What i need is a change that alow to select just the first two cells of the row of the activecells. When i click in the cell, i need that the cell of the column "$I16" and "$J16" (16 is the first line of my table) of that row became interior color (=9359529). The code is this: 
Dim lTarget As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Row >= 16 Then

If Not lTarget Is Nothing Then

lTarget.EntireRow.Interior.ColorIndex = 0
End If

Target.EntireRow.Interior.Color = 9359529

Set lTarget = Target
End If
End Sub

Can you help me? I had try to change this code but the only thing i can as the select the interior color of the cell target and not the column "$I" and "$J" in that specific row.Thank you for your help.
Luis Lopes
This comment was minimized by the moderator on the site
I know that you proposed a solution but the solution comes with another problem as you described below: "The only problem with having this code active is that you can no longer change the active cell color as it changes back to what it was before you clicked it. I suggest that if you need to change the highlight colors on the sheet, do so with macros disabled or change the sub name for a second so it doesn't trigger when you are clicking on cells". This is not an acceptable alternative for me. I need to be able to change the colors in the cells when the macro is active. Do you have a solution for this this problem. If you come up with a solution for this problem please republish your corrected macro the new macro in full (rather than proposing patches to your original macro because I am technically challenged as far as macro are concerned).
This comment was minimized by the moderator on the site
I tried your macro by copying and pasting it into my Excel file. I did change one thing in the macro though. I changed the color index from 6 to 24 (to a color different than the colors I am currently using in my macro). It worked very nicely and I liked it a lot but then started causing a problem for me. I have a lot of cells filled with with colors in my Excel. The macro started removing the color fill from every cell touched. I don't know how to stop the macro's this odd behavior. I did not have any choice but to remove the macro from my file. I still like to use this macro if someone can help me to fix it.
This comment was minimized by the moderator on the site
That was super helpful, thank you.
This comment was minimized by the moderator on the site
Anyway you can do the left adjacent cell to highlight instead of active cell? Or a range of cells around the activecell?
This comment was minimized by the moderator on the site
Thank you, but use this with caution. It has the undesirable counter effect of not letting undo. Is there any solution for that?
This comment was minimized by the moderator on the site
But i am unable to do undo option and lose the previously assigned cell color also.
Please provide solution
This comment was minimized by the moderator on the site
Perfect solution as I always tend to loose the track of the highlighted cell during "Find and Select" operation. Thanks a lot.
This comment was minimized by the moderator on the site
Great!! But what if I don't want to lose the previously assigned cell color? That would be greater to know.
This comment was minimized by the moderator on the site
Use a conditional format on the cells you want to protect.
This comment was minimized by the moderator on the site
Instead of "ColorIndex" which has a limited set of 255 values (meaning any custom colors are lost), use "Color" instead. You'll need to store the old value in a new static long variable and also generate the highlight color you want with the RGB function. The only problem with having this code active is that you can no longer change the active cell color as it changes back to what it was before you clicked it. I suggest that if you need to change the highlight colors on the sheet, do so with macros disabled or change the sub name for a second so it doesn't trigger when you are clicking on cells, then just rename it back to normal to "re-activate" it. Here is my code:

Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)

Static xLastRng As Range
Static xLastRngColor As Long

On Error Resume Next

xLastRng.Interior.Color = xLastRngColor
xLastRngColor = Target.Interior.Color
Target.Interior.Color = RGB(255, 255, 0) 'compose whatever highlight color you want with RGB values, I am using yellow here
Set xLastRng = Target

End Sub
This comment was minimized by the moderator on the site
work.... great...
This comment was minimized by the moderator on the site
Yes, I would like to know this as well. How would you keep the previously selected cells highlight for tracking purposes?
This comment was minimized by the moderator on the site
See my comment above.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations