Loncat ke daftar isi utama

Bagaimana cara menduplikasi baris berdasarkan nilai sel di kolom?

Misalnya, saya memiliki rentang data yang berisi daftar angka di kolom D, dan sekarang, saya ingin menduplikasi seluruh baris beberapa kali berdasarkan nilai numerik di kolom D untuk mendapatkan hasil berikut. Bagaimana saya bisa menyalin baris beberapa kali berdasarkan nilai sel di Excel?

Gandakan baris beberapa kali berdasarkan nilai sel dengan kode VBA

Salin dan sisipkan baris berdasarkan jumlah waktu tertentu dengan alat praktis - Kutools for Excel


Gandakan baris beberapa kali berdasarkan nilai sel dengan kode VBA

Untuk menyalin dan menduplikasi seluruh baris beberapa kali berdasarkan nilai sel, kode VBA berikut dapat membantu Anda, lakukan seperti ini:

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

2. Klik Menyisipkan > Modul, dan tempel kode berikut di Modul Jendela.

Kode VBA: Baris duplikat beberapa kali berdasarkan nilai sel:

Sub CopyData()
'Updateby Extendoffice
    Dim xRow As Long
    Dim VInSertNum As Variant
    xRow = 1
    Application.ScreenUpdating = False
    Do While (Cells(xRow, "A") <> "")
        VInSertNum = Cells(xRow, "D")
        If ((VInSertNum > 1) And IsNumeric(VInSertNum)) Then
           Range(Cells(xRow, "A"), Cells(xRow, "D")).Copy
           Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "D")).Select
           Selection.Insert Shift:=xlDown
           xRow = xRow + VInSertNum - 1
        End If
        xRow = xRow + 1
    Loop
    Application.ScreenUpdating = False
End Sub

3. Lalu tekan F5 kunci untuk menjalankan kode ini, seluruh baris telah digandakan beberapa kali berdasarkan nilai sel di kolom D yang Anda butuhkan.

Note: Dalam kode di atas, huruf A menunjukkan kolom awal rentang data Anda, dan hurufnya D adalah huruf kolom yang Anda inginkan untuk menduplikasi baris berdasarkan. Harap ubah sesuai kebutuhan Anda.

Salin dan sisipkan baris berdasarkan jumlah waktu tertentu dengan alat praktis - Kutools for Excel

Jika Anda tidak terbiasa dengan kode VBA dan tidak dapat mengubah sendiri parameter dalam kode dengan benar. Dalam hal ini, Kutools untuk Excel's Gandakan Baris / Kolom Berdasarkan Nilai Sel fitur dapat membantu Anda menyalin dan menyisipkan baris beberapa kali berdasarkan nilai sel hanya dengan tiga klik.

Tips: Untuk menerapkan ini Duplikat Baris / Kolom berdasarkan nilai sel fitur, Anda harus unduh Kutools untuk Excel pertama.
  1. Klik Kutools > Menyisipkan > Duplikat Baris/Kolom Berdasarkan Nilai Sel untuk mengaktifkan fitur ini;
  2. Lalu pilih Salin dan sisipkan baris opsi, dan tentukan sel dari Sisipkan Rentang dan Ulangi Kali secara terpisah di kotak dialog.

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 (41)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi All,
Can anyone give me the code to copy whole table at the same time?.
This comment was minimized by the moderator on the site
Hello, Aparna,
Maybe the following article can help you.
https://www.extendoffice.com/documents/excel/3682-excel-copy-and-insert-row-multiple-times.html#a2
Please view it, if you have any other problem, please comment here.
This comment was minimized by the moderator on the site
Is there any way to get this to work on a shared workbook? it works perfectly until I share the workbook then i get "insert method of range class failed"
This comment was minimized by the moderator on the site
Bonjour,
Merci pour ce code qui fonctionne bien.
Par contre dans mon tableau j'ai une date pour chaque ligne:
J'aimerai qu'elle s'incrémente au fur et à mesure des duplications de lignes et en automatique, car il y a plus de 1000 dossiers différents.

N° dossier Date Nb de jours
2101007 29/01/2021 49
2110002 11/10/2021 22
2008006 31/08/2020 132

pour donner:
N° dossier Date Nb de jours
2101007 29/01/2021 49
2101007 30/01/2021 49
...

Est-ce possible ?
Merci par avance.
This comment was minimized by the moderator on the site
Thank you so much for this!
This comment was minimized by the moderator on the site
What if I wanted to do the above (nice job btw) but what if I wanted to change the dates by “X” days when I add the rows? Like a reoccurring event in a calendar. 
This comment was minimized by the moderator on the site
This is PERFECTION! Short Sweet and to the point as well as easily adaptable!
THANK YOU!
This comment was minimized by the moderator on the site

this is wondeful thank you so much
This comment was minimized by the moderator on the site
I tried running it by pressing F5 and a pop up message below:
"Compile Error:Sub or function not defined."
What am I doing wrong? I adjusted column A and changed A & D as needed.
This comment was minimized by the moderator on the site
Hi, this does not work for me. I copy the code, change the column letter D to the column letter that I want to duplicate rows based upon, and... nothing happens when I run the code. I have enabled macros and tried on two different computers. What am I doing wrong?
This comment was minimized by the moderator on the site
Hi, Sean,
Note: In the above code, the letter A indicates the start column of your data range, and the letter D is the column letter that you want to duplicate the rows based on. Please change them to your need.
Have you adjust the column A of your data? please check it, thank you!

This comment was minimized by the moderator on the site
Is it possible to adjust the code to create a new sheet, keeping the original sheet untouched?
This comment was minimized by the moderator on the site
Hello,If you want to keep your original data, please copy and paste the data into another new sheet, and then apply the code as you need.
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