Skip i'r prif gynnwys

Sut i ddyblygu rhesi yn seiliedig ar werth celloedd mewn colofn?

Er enghraifft, mae gen i ystod o ddata sy'n cynnwys rhestr o rifau yng ngholofn D, a nawr, rydw i eisiau dyblygu'r rhesi cyfan nifer o weithiau yn seiliedig ar y gwerthoedd rhifol yng ngholofn D i gael y canlyniad canlynol. Sut allwn i gopïo'r rhesi sawl gwaith yn seiliedig ar werthoedd y celloedd yn Excel?

Rhesi dyblyg sawl gwaith yn seiliedig ar werthoedd celloedd gyda chod VBA

Copïwch a mewnosodwch resi yn seiliedig ar nifer penodedig o weithiau gydag offeryn defnyddiol - Kutools ar gyfer Excel


Rhesi dyblyg sawl gwaith yn seiliedig ar werthoedd celloedd gyda chod VBA

I gopïo a dyblygu'r rhesi cyfan sawl gwaith yn seiliedig ar werthoedd y celloedd, gall y cod VBA canlynol eich helpu, gwnewch fel hyn:

1. Daliwch i lawr y ALT + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Modiwlau Ffenestr.

Cod VBA: Rhesi dyblyg sawl gwaith yn seiliedig ar werth celloedd:

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. Yna pwyswch F5 yn allweddol i redeg y cod hwn, mae'r rhesi cyfan wedi'u dyblygu sawl gwaith yn seiliedig ar werth y gell yng ngholofn D yn ôl yr angen.

Nodyn: Yn y cod uchod, y llythyr A yn nodi colofn gychwyn eich ystod ddata, a'r llythyr D yw'r llythyr colofn rydych chi am ddyblygu'r rhesi yn seiliedig arno. Os gwelwch yn dda eu newid i'ch angen.

Copïwch a mewnosodwch resi yn seiliedig ar nifer penodedig o weithiau gydag offeryn defnyddiol - Kutools ar gyfer Excel

Os nad ydych chi'n gyfarwydd â'r cod VBA ac yn methu â newid y paramedrau yn y cod yn gywir ar eich pen eich hun. Yn yr achos hwn, y Kutools ar gyfer Excel's Rhesi / Colofnau Dyblyg yn Seiliedig ar Werth Cell Gall nodwedd eich helpu i gopïo a mewnosod rhesi sawl gwaith yn seiliedig ar werthoedd y gell gyda dim ond tri chlic.

Awgrymiadau: I gymhwyso hyn Rhesi / Colofnau Dyblyg yn seiliedig ar werth celloedd nodwedd, dylech lawrlwythwch y Kutools ar gyfer Excel gyntaf.
  1. Cliciwch Kutools > Mewnosod > Rhesi/Colofnau Dyblyg yn seiliedig ar Werth Cell i alluogi'r nodwedd hon;
  2. Yna, dewiswch Copïo a mewnosod rhesi opsiwn, a nodi celloedd y Mewnosod Ystod ac Ailadroddwch Amseroedd ar wahân yn y blwch deialog.

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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