Piškotki nam pomagajo dostaviti naših storitev. Z uporabo naših storitev se strinjate z našo uporabo piškotkov.
Namig: drugi jeziki so prevedeni v Google. Lahko obiščete English različico te povezave.
Vpiši se
x
or
x
x
Registracija
x

or

Kako kopirati vrstice na podlagi vrednosti celice v stolpcu?

Na primer, imam nabor podatkov, ki vsebujejo seznam številk v stolpcu D, zdaj pa želim večkrat podvojiti celotne vrstice na podlagi številčnih vrednosti v stolpcu D, da bi dobili naslednji rezultat. Kako bi lahko vrstice večkrat kopirali glede na vrednosti celic v Excelu?

doc podvoji vrstice po celici 1

Podvojene vrstice večkrat temeljijo na vrednostih celice s kodo VBA


puščica modra desno mehurček Podvojene vrstice večkrat temeljijo na vrednostih celice s kodo VBA

Če želite kopirati in podvojiti celotne vrstice večkrat glede na vrednosti celice, vam lahko pomaga naslednja koda VBA, storite tako:

1. Drži dol ALT + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno.

2. Kliknite Vstavi > Moduli, in prilepite naslednjo kodo v Moduli Okno.

VBA koda: podvojene vrstice večkrat na podlagi vrednosti celice:

Sub CopyData()
'Updateby Extendoffice 20160922
    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. Nato pritisnite F5 ključ za zagon te kode, so bile celotne vrstice podvojene večkrat glede na vrednost celice v stolpcu D, kot jo potrebujete.

Opombe: V zgornji kodi pismo A označuje začetni stolpec vašega podatkovnega obsega in črko D je črka stolpca, na katero želite podvojiti vrstice na podlagi. Prosimo, spremenite jih na svoje potrebe.



Priporočena orodja za produktivnost

Office Tab

zlata zvezda1 Pripeljite priročne zavihke v programsko opremo Excel in drugo programsko opremo, tako kot Chrome, Firefox in novi Internet Explorer.

Kutools za Excel

zlata zvezda1 Neverjetno! Povečajte produktivnost v minutah 5. Ne potrebujete posebnih veščin, prihranite dve uri vsak dan!

zlata zvezda1 300 Nove funkcije za Excel, naredite Excel precej enostavno in zmogljivo:

  • Spoji celice / vrstice / stolpci brez izgube podatkov.
  • Združite in konsolidirajte več listov in delovnih zvezkov.
  • Primerjajte obsege, kopiraj več razponov, pretvorite besedilo v datum, pretvorbo enote in valute.
  • Count by Colors, Paging Subtotals, Advanced Sort in Super Filter,
  • Več Izberite / Vstavi / Izbriši / Besedilo / Format / Povezava / Komentar / Delovne knjige / Delovni listi ...

Zaslonski posnetek Kutools za Excel

Say something here...
symbols left.
You are guest ( Sign Up? )
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.
    KAS · 1 months ago
    Is there a way to update the module to only duplicate new data? I'm working on an ongoing document and do not want the code to duplicate data that has been previously duplicated.
  • To post as a guest, your comment is unpublished.
    Gerardo Enrique Heras Araujo · 2 months ago
    hi, for me is no working, I want to remove letters and number duplicate is possible?
  • To post as a guest, your comment is unpublished.
    Naomi · 2 months ago
    This script seems to be exactly what I need, however, when I run it I am getting an error on the line Selection.Insert Shift:=x1Down

    Any suggestions on how I fix this?
  • To post as a guest, your comment is unpublished.
    Manuel F · 2 months ago
    Thanks! it has been a great solution for all my troubles!
  • To post as a guest, your comment is unpublished.
    Leah · 3 months ago
    Hello, this worked great. However, I have a report with 1000 entries and the code stopped duplicating around entry 480. Is there something that I can add so that it completes the action on the entire report?
    • To post as a guest, your comment is unpublished.
      skyyang · 3 months ago
      Hello, Leah,
      I have tested the code in 2000 rows, and it works well.
      Could you send your worksheet to me for testing the code?
      My email address is skyyang@extendoffice.com
      Look forward to your reply!
      • To post as a guest, your comment is unpublished.
        Leah · 3 months ago
        Hello! I got it to work. It was an error on my side, the report had a few blank rows that were hidden that were causing the script to stop looping. It worked for my report with 8,000 rows! Thank youQ