Loncat ke daftar isi utama

Bagaimana cara mengulang baris sampai kosong di kolom Excel?

Berikut adalah kolom panjang dengan data yang termasuk beberapa sel kosong, dan Anda ingin mengulang baris hingga bertemu sel kosong. Di Excel, tidak ada fitur bawaan yang dapat menangani pekerjaan ini, tetapi saya dapat memperkenalkan beberapa makro untuk membantu Anda.

Ulangi baris sampai kosong dengan VBA


panah gelembung kanan biru Ulangi baris sampai kosong dengan VBA

1. tekan Alt + F11 kunci untuk mengaktifkan Microsoft Visual Basic untuk Aplikasi jendela.

2. klik Menyisipkan > Modul, dan tempel kode di bawah ini ke skrip kosong.

VBA: Ulangi sampai kosong

Sub Test1()
'UpdatebyExtendoffice20161222
      Dim x As Integer
      Application.ScreenUpdating = False
      ' Set numrows = number of rows of data.
      NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
      ' Select cell a1.
      Range("A1").Select
      ' Establish "For" loop to loop "numrows" number of times.
      For x = 1 To NumRows
         ' Insert your code here.
         ' Selects cell down 1 row from active cell.
         ActiveCell.Offset(1, 0).Select
      Next
      Application.ScreenUpdating = True
End Sub

doc loop sampai kosong 1

Dalam kode, A1 adalah sel pertama yang ingin Anda putar, Anda dapat mengubahnya sesuai kebutuhan.

3. tekan F5 kunci untuk memulai perulangan kolom, maka kursor akan berhenti di sel kosong yang pertama bertemu.
doc loop sampai kosong 2

Note: Jika Anda ingin mengulang data hingga bertemu sel kosong terus menerus, Anda dapat menggunakan kode makro ini.

Sub LoopThroughUntilBlanks()
'UpdatebyExtendoffice20161222
      ' Select cell A2, *first line of data*.
      Dim xrg As Range
      On Error Resume Next
      Set xrg = Application.InputBox _
        (Prompt:="first cell select..", Title:="Kutools for Excel", Type:=8)
      xrg.Cells(1, 1).Select
      ' Set Do loop to stop when two consecutive empty cells are reached.
      Application.ScreenUpdating = False
      Do Until IsEmpty(ActiveCell) And IsEmpty(ActiveCell.Offset(1, 0))
         ' Insert your code here.
         '
         ' Step down 2 rows from present location.
         ActiveCell.Offset(2, 0).Select
      Loop
      Application.ScreenUpdating = False
End Sub

Kemudian Anda perlu memilih sel pertama yang ingin Anda putar dari dalam Kutools untuk Excel dialog, klik OK, lalu kursor berhenti di sel kosong berkelanjutan pertama.

doc loop sampai kosong 3 doc loop sampai kosong 4

Gabungkan beberapa lembar / Buku Kerja dengan mudah menjadi satu lembar atau Buku Kerja

Untuk menggabungkan beberapa lembar atau buku kerja ke dalam satu lembar atau buku kerja mungkin membosankan di Excel, tapi dengan Menggabungkan Fungsi di Kutools for Excel, Anda bisa menggabungkan lusinan lembar / buku kerja menjadi satu lembar atau buku kerja, juga, Anda bisa menggabungkan lembaran menjadi satu dengan beberapa klik saja.  Klik untuk uji coba gratis 30 hari berfitur lengkap!
menggabungkan lembaran
 
Kutools for Excel: dengan lebih dari 300 add-in Excel yang praktis, gratis untuk dicoba tanpa batasan dalam 30 hari.

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 (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
The first VBA produces the wrong result in cases when there is one or zero rows of data.

You probably need something like

If Range("A1").Value = "" Then
NumRows = 0
ElseIf Range("A1").Offset(1, 0).Value = "" Then
NumRows = 1
Else
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
End If
This comment was minimized by the moderator on the site
The loop works for me except it loops through every single row regardless of it being blank or not.
This comment was minimized by the moderator on the site
Lets say I have a ton of rows...any tricks on making this run faster?
This comment was minimized by the moderator on the site
Can you please explain what is the condition to stop looping? What makes you break out of the loop in Test1()?
This comment was minimized by the moderator on the site
It will stop while meeting the first blank in the column
This comment was minimized by the moderator on the site
Its looping a column not a row
This comment was minimized by the moderator on the site
In order to loop through a column, you must go by row number.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations