How to insert one Row from duplicate row data and fill insert row with packing Number

SunnyAlv

Active Member
Joined
May 23, 2023
Messages
329
Office Version
  1. 365
Platform
  1. Windows
Hi guys, im have Problem and i hope u can help me :)

i just want to insert one row for every duplicate row data/ Table and fill that with something from each duplicate data, u can see image below


Table A --> Table B --> Table C

I Hope u help me With VBA

Thankss ;)


1701147219922.png
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I'm assuming you want the changes to take place where table A currently sits? If so, try the following code on a copy of your worksheet. It assumes the layout of your data is as per your image: starts in B2.
VBA Code:
Option Explicit
Sub Fix_Format()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, r As Range
    Set ws = Worksheets("Sheet1")   '<-- *** Change to actual sheet name ***
    Set r = ws.Range("B2", ws.Cells(Rows.Count, "D").End(xlUp))
    Dim a, i As Long, c As Range
    a = r
    With ws
        For i = r.Rows.Count + 1 To 3 Step -1
            If a(i - 1, 2) <> a(i - 2, 2) Then
                .Rows(i).Insert
            End If
        Next i
        For i = 3 To .Cells(Rows.Count, "D").End(xlUp).Row + 1
            If .Cells(i, 2) = "" Then
                .Cells(i, 2) = "JOB " & .Cells(i - 1, 4)
                .Cells(i, 2).Resize(, 3).Interior.Color = vbYellow
            End If
        Next i
        Set c = .Range("B2:D" & ws.Cells(Rows.Count, "B").End(xlUp).Row)
        With c.Borders
            .LineStyle = xlContinuous
            .Color = vbBlack
            .Weight = xlThin
        End With
    End With
    Application.ScreenUpdating = True
End Sub

Before:
Book1
ABCDE
1
21ABC123
32ABC123
43ACB121
54CBA133
65AAA111
76AAA111
87AAA111
98BBB222
10
Sheet1


After:
Book1
ABCDE
1
21ABC123
32ABC123
4JOB 123
53ACB121
6JOB 121
74CBA133
8JOB 133
95AAA111
106AAA111
117AAA111
12JOB 111
138BBB222
14JOB 222
15
Sheet1
 
Upvote 0
Solution
Saya berasumsi Anda ingin perubahan terjadi di tempat tabel A saat ini berada? Jika ya, coba kode berikut pada salinan lembar kerja Anda. Ini mengasumsikan tata letak data Anda sesuai gambar Anda: dimulai di B2.
[KODE=vba]
Opsi Eksplisit
Sub Fix_Format()
Aplikasi.Pembaruan Layar = Salah
Redupkan sebagai Lembar Kerja, r Sebagai Rentang
Set ws = Worksheets("Sheet1") '<-- *** Ubah ke nama sheet sebenarnya ***
Setel r = ws.Range("B2", ws.Cells(Rows.Count, "D").End(xlUp))
Redupkan a, i Selama, c Sebagai Rentang
sebuah = r
Dengan ws
Untuk i = r.Rows.Count + 1 Sampai 3 Langkah -1
Jika a(i - 1, 2) <> a(i - 2, 2) Maka
.Baris(i).Sisipkan
Berakhir jika
berikutnya saya
Untuk i = 3 Ke .Cells(Rows.Count, "D").End(xlUp).Row + 1
Jika .Cells(i, 2) = "" Lalu
.Cells(i, 2) = "PEKERJAAN" & .Cells(i - 1, 4)
.Cells(i, 2).Resize(, 3).Interior.Color = vbYellow
Berakhir jika
berikutnya saya
Setel c = .Range("B2:D" & ws.Cells(Rows.Count, "B").End(xlUp).Row)
Dengan c.Borders
.LineStyle = xlTerus menerus
.Warna = vbHitam
.Berat = xlTipis
Berakhir dengan
Berakhir dengan
Aplikasi.Pembaruan Layar = Benar
Akhiri Sub
[/KODE]

Sebelum:
Buku1
A[/XH ][XH=w:48]BCDE1[ /XD]
21ABC[ /XD][XD=h:c]123
3ABC123
3ACB121[ /XD][XD]
54133
65AAA11176AAA
8 7AAA111
9[/XH ][XD=ch:14.4][/XD][XD=h:c]8[/XD][XD=h:c]BBB[/XD][XD=h:c]222[/XD][XD ][/XD]
Sheet1
[ /XR][XR] [XD] [XD =h:c]2[/XD] [XH ]4[/XH] [XD =h:c]CBA[/XD] [/ XR][XR] [XD =h:c]111[/XD] [XH] XD][XD][/XD][/XR]


Setelah:
Buku1
A[/XH ][XH=w:48]BCDE11ABC123[/ XD][XD=cls:bl]
32ABC123
4PEKERJAAN 123[/XD ][XD=cls:bl]
53ACB121
6PEKERJAAN 121
74CBA133
8PEKERJAAN 133
95AAA111
106AAA111
11 7AAA111
12PEKERJAAN 111
138 BBB222[ /XD]
14PEKERJAAN 222
15[/ XD][XD=cls:bt]
Sheet1
[ /XR][XR] [ XD=cls:bl][/XD] [XD =cls:bl][/XD] [ XD=cls:bl][/XD] [XD=cls:bl]
Dangg its work bro, thanks
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top