autonumber and get value repeatedly based on duplicated each item

Hasson

Active Member
Joined
Apr 8, 2021
Messages
386
Office Version
  1. 2016
Platform
  1. Windows
I have this data in sheet1
7.xlsx
AB
1CODEVALUE
2A-10001000
3A-10011001
4A-10021002
5A-10031003
6A-10041004
7A-10051005
8A-10061006
9A-10071007
10A-10081008
SHEET1

and the result in sheet2
7.xlsx
ABCD
1S.NITEMDATEVALUE
21A-10001/1/20211000
31A-10001/2/20211000
41A-10001/3/20211000
52A-10011/4/20211001
62A-10011/5/20211001
72A-10011/6/20211001
SHEET2

so the result should be in COL A,D based on fill data in col B, . it should match with COL A in sheet 1 then shoud autonumber and repeat the values for each repeated item
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Each item must repeat 3 times, that is, A-1000 3 times, A-1001 3 times, A-1002 3 times and so on?
 
Upvote 0
Try this

VBA Code:
Sub autonumber_value()
  Dim c As Range, i As Long, d As Date
  d = DateSerial(2021, 1, 1)
  For Each c In Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("A" & Rows.Count).End(3))
    For i = 1 To 3
      Sheets("Sheet2").Range("A" & Rows.Count).End(3)(2).Resize(, 4).Value = Array(c.Row - 1, c, d, c.Offset(, 1))
      d = d + 1
    Next
  Next
End Sub
 
Upvote 0
Solution
wow ! that's very impressive . may you mod the code and create the headers (sn,item,date, value) with the borders and headers in sheet2 ,please?
 
Upvote 0
create the headers (sn,item,date, value)
Sub autonumber_value()
Dim c As Range, i As Long, d As Date
d = DateSerial(2021, 1, 1)
Sheets("Sheet2").Range("A1:D1").Value = Array("S.N", "ITEM", "DATE", "VALUE")
For Each c In Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("A" & Rows.Count).End(3))
For i = 1 To 3
Sheets("Sheet2").Range("A" & Rows.Count).End(3)(2).Resize(, 4).Value = Array(c.Row - 1, c, d, c.Offset(, 1))
d = d + 1
Next
Next
End Sub

You can set the color and border format the first time.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,483
Messages
6,113,919
Members
448,533
Latest member
thietbibeboiwasaco

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