autonumber and get value repeatedly based on duplicated each item

Hasson

Board Regular
Joined
Apr 8, 2021
Messages
115
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
13,573
Office Version
  1. 2007
Platform
  1. Windows
Each item must repeat 3 times, that is, A-1000 3 times, A-1001 3 times, A-1002 3 times and so on?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
13,573
Office Version
  1. 2007
Platform
  1. Windows
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
 
Solution

Hasson

Board Regular
Joined
Apr 8, 2021
Messages
115
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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?
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
13,573
Office Version
  1. 2007
Platform
  1. Windows
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.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
13,573
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,141,130
Messages
5,704,452
Members
421,350
Latest member
jake9951

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
Top