Loncat ke daftar isi utama

Bagaimana cara menyorot tajuk kolom atau kolom jika disaring di Excel?

Untuk tabel dengan banyak kolom, tidak mudah untuk mengetahui kolom mana yang difilter secara sekilas karena tidak ada simbol yang jelas untuk kolom yang difilter kecuali untuk a menandai. Jika Anda ingin membuat kolom yang difilter menonjol dalam sebuah tabel, metode dalam artikel ini dapat membantu Anda.

Sorot header kolom atau seluruh kolom jika difilter dengan kode VBA


Sorot header kolom atau seluruh kolom jika difilter dengan kode VBA

Seperti gambar di bawah ini yang ditampilkan, Anda perlu menyorot seluruh kolom atau hanya tajuk kolom jika kolom ini difilter dalam rentang tabel, harap terapkan kode VBA berikut.

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

2. Di jendela Microsoft Visual Basic for Applications, klik Menyisipkan > Modul. Kemudian salin kode VBA di bawah ini ke jendela Modul.

Kode VBA: Sorot header kolom jika kolom difilter

Sub HighLightTitle()
'Updated by Extendoffice 2017/9/12
    Dim xRg As Range
    Dim I As Integer
    Dim xCount As Long
    Dim xRgCol As Long
    Dim xAddress As String
    Dim xFilterCount As Long
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the first cell of the table range:", "KuTools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xRg.Select
    With xRg(1).Parent.AutoFilter
        xFilterCount = .Range.Columns.Count
        xRgCol = xRg.Offset(1).Column - .Range.Column + 1
        For I = xRgCol To xFilterCount
            xCount = xRg.Offset(, I - xRgCol).Column - .Range.Column + 1
            With .Filters(xCount)
                If .On Then
                    xRg.Offset(, I - xRgCol).Interior.Color = 16736553
                End If
            End With
        Next
    End With
End Sub

Untuk menyorot seluruh kolom jika difilter dalam tabel, harap salin dan tempel kode VBA di bawah ini ke jendela Modul.

Kode VBA: Sorot seluruh kolom jika difilter

Sub HighLightCols()
'Updated by Extendoffice 2017/9/12
    Dim xRg As Range
    Dim xCount As Long
    Dim xRgCol As Long
    Dim xAddress As String
    Dim xRgFilter As Range
    Dim xFilterCount As Long
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the first cell of the table range:", "KuTools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xRg.Select
    With xRg(1).Parent.AutoFilter
        xFilterCount = .Range.Columns.Count
        xRgCol = xRg(1).Column - .Range.Column + 1
        For I = xRgCol To xFilterCount
            xCount = xRg.Offset(, I - xRgCol).Column - .Range.Column + 1
            With .Filters(xCount)
                Set xRgFilter = xRg.Offset(, I - xRgCol).Parent.AutoFilter.Range.Columns(xCount)
                If .On Then
                    xRgFilter.Interior.Color = 16736553
                End If
            End With
        Next
    End With
End Sub

3. tekan F5 kunci untuk menjalankan kode. Dalam bermunculan Kutools untuk Excel kotak dialog, pilih sel pertama dari tabel yang Anda perlukan untuk menyorot tajuk kolom yang difilter atau seluruh kolom yang difilter, lalu klik OK .

Kemudian tajuk kolom atau seluruh kolom akan langsung disorot jika kolom difilter dalam tabel tertentu. Lihat tangkapan layar:

Sorot tajuk kolom jika kolom difilter dalam tabel:

Sorot seluruh kolom jika difilter di tabel:

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 (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
solution that can help create updated vba is TO add additional duplicate first raw in row A1, Row A2 should be the beginning of the filtered data ( exact duplicate of all data in Row A1 - Row A1 and A2 should me same ), so we always have one header line without filter drop down icon and with OG format, once the macro is ran with few columns filtered it will highlight the filtered column as usual and after removing the desired columns filter or all columns filter it should copy the format in A1 Column, for the columns with no filtered sorting can this be done ?
This comment was minimized by the moderator on the site
this would be fantastic for me, but I couldn't make it work. I used the code to color the whole column. when I filtered the first time, the column turned blue. however when I cleared the filter, the blue remained. Afterwards, filtering another column had no effect. so at the moment I am left with one blue column. using latest Excel of Office 365.
This comment was minimized by the moderator on the site
I had the same issue. Once the column is unfiltered. The column remained blue. Also, when do you filter a new column, it's unchanged. The vba doesn't make it highlighted in the new filter column.
This comment was minimized by the moderator on the site
Hi,
Thank you for your comment.
The problem you mentioned is too complicated to acheive now. We will try our best to solve it as soon as possible and let you know after we figure it out.
This comment was minimized by the moderator on the site
To Correct this, change:
If .On Then

xRg.Offset(, I - xRgCol).Interior.Color = 16736553

End If

To:
If .On Then

xRg.Offset(, I - xRgCol).Interior.Color = 16736553

Else

xRg.Offset(, I - xRgCol).Interior.Color = 16777215

End If



Not it will remove the color.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations