Skip to main content

Conas sraitheanna a mhacasamhlú bunaithe ar luach cille i gcolún?

Údar: Xiaoyang Athraithe Deiridh: 2023-05-04

Mar shampla, tá raon sonraí agam ina bhfuil liosta uimhreacha i gcolún D, agus anois, ba mhaith liom na sraitheanna iomlána a mhacasamhlú roinnt uaireanta bunaithe ar na luachanna uimhriúla i gcolún D chun an toradh seo a leanas a fháil. Conas a d’fhéadfainn na sraitheanna a chóipeáil arís agus arís eile bunaithe ar na luachanna cille in Excel?

Sraitheanna dúblacha arís agus arís eile bunaithe ar luachanna cille le cód VBA

Cóipeáil agus cuir isteach sraitheanna bunaithe ar líon sonraithe uaireanta le huirlis láimhe - Kutools le haghaidh Excel


Sraitheanna dúblacha arís agus arís eile bunaithe ar luachanna cille le cód VBA

Chun na sraitheanna iomlána a chóipeáil agus a mhacasamhlú arís agus arís eile bunaithe ar na luachanna cille, d’fhéadfadh an cód VBA seo a leanas cabhrú leat, déan mar seo le do thoil:

1. Coinnigh síos an ALT + F11 eochracha a oscailt Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Cliceáil Ionsáigh > Modúil, agus greamaigh an cód seo a leanas sa Modúil Fuinneog.

Cód VBA: Sraitheanna dúblacha arís agus arís eile bunaithe ar luach cille:

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. Ansin brúigh F5 eochair chun an cód seo a rith, rinneadh na sraitheanna iomlána a mhacasamhlú arís agus arís eile bunaithe ar luach na cille i gcolún D de réir mar is gá duit.

nótaí: Sa chód thuas, an litir A léiríonn sé colún tosaigh do raon sonraí, agus an litir D an litir cholúin ar mhaith leat na sraitheanna a mhacasamhlú bunaithe uirthi. Athraigh iad le do riachtanas le do thoil.

Cóipeáil agus cuir isteach sraitheanna bunaithe ar líon sonraithe uaireanta le huirlis láimhe - Kutools le haghaidh Excel

Mura bhfuil tú eolach ar an gcód VBA agus mura bhfuil tú in ann na paraiméadair sa chód a athrú i gceart leat féin. Sa chás seo, beidh an Kutools le haghaidh Excel's Sraitheanna / Colúin Dhúblacha Bunaithe ar Luach Cille is féidir leis an ngné seo cabhrú leat sraitheanna éagsúla a chóipeáil agus a chur isteach bunaithe ar na luachanna cille gan ach trí chliceáil.

Leideanna: Chun é seo a chur i bhfeidhm Sraitheanna / Colúin Dúblacha bunaithe ar luach cille gné, ba chóir duit Íoslódáil an kutools do excel an chéad.
  1. cliceáil Kutools > Ionsáigh > Rónna/Colúin Dhúblacha Bunaithe ar Luach Cille chun an ghné seo a chumasú;
  2. Ansin, roghnaigh Cóipeáil agus cuir isteach sraitheanna rogha, agus sonraigh cealla an Ionsáigh Raon agus Déan arís ar leithligh sa bhosca dialóige.

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
Comments (43)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
the formula worked when the data set in a column has no blank row. however, it won't work if there is a blank row separating the rows with data. is there any script to add to work it just like that?
This comment was minimized by the moderator on the site
Hello, Charies,
Yes, as you said, the code will not work if there are blank rows in the data range. To solve this issue, please apply the below modified code:
Sub CopyData()
    ' Update by Extendoffice
    Dim xRow As Long
    Dim VInSertNum As Variant
    Dim LastRow As Long
    
    Application.ScreenUpdating = False
    ' Find the last row with data in column A
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row

    xRow = 1
    Do While xRow <= LastRow
        ' Check if there is data in column A of the current row
        If Cells(xRow, "A") <> "" Then
            VInSertNum = Cells(xRow, "D")
            If IsNumeric(VInSertNum) And VInSertNum > 1 Then
                Range(Cells(xRow, "A"), Cells(xRow, "D")).Copy
                Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "D")).Select
                Selection.Insert Shift:=xlDown
                ' Update LastRow due to insertion
                LastRow = LastRow + VInSertNum - 1
                xRow = xRow + VInSertNum - 1 ' Move xRow to the row after the last inserted
            End If
        End If
        xRow = xRow + 1
    Loop

    Application.ScreenUpdating = True
End Sub



Please have a try, hope it can help you!
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!

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