Generate unique numbers

STEEL010

Board Regular
Joined
Dec 29, 2017
Messages
76
Hi There,


I have a challenging question....


I have an existing macro that split the mastersheet into splitted sheets in the same workbook and it saves also the splitted sheet.
And now I want that it generate for every splitted sheet a unique number in a cell with an prefix like "invoice" and that the last created unique number will generated in mastersheet so it goes on in the future with the last number and counting.


Is this possible?



Greetings,


Steel010
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi,

Your question is ... rather generic ... :smile:

With Excel ... everything is possible ... so, the short answer is : Yes :wink:
 
Upvote 0
This is the splitcode, where and how can I wright the code to generate an unique automatic numbering

Sub Split()
Dim Cl As Range
Dim ws As Worksheet
Dim Ky As Variant

Application.ScreenUpdating = False
Set ws = Sheets("Invoice")
With CreateObject("scripting.dictionary")
For Each Cl In ws.Range("D2", ws.Range("D" & Rows.Count).End(xlUp).Offset(-1))
If Not .Exists(Cl.Value) And Cl.Value <> "" Then .Add Cl.Value, Nothing
Next Cl
For Each Ky In .Keys
ws.Range("A1").AutoFilter 4, Ky
Sheets.Add(, ws).Name = Ky
ws.AutoFilter.Range.EntireRow.Copy Sheets(Ky).Range("A1")
Sheets(Ky).Columns.AutoFit
Next Ky
End With
ws.AutoFilterMode = False
ws.Activate
 
Upvote 0
Hi again

Code:
[COLOR=#333333]Sub Split()[/COLOR]
[COLOR=#333333]Dim Cl As Range[/COLOR]
[COLOR=#333333]Dim ws As Worksheet[/COLOR]
[COLOR=#333333]Dim Ky As Variant[/COLOR]

[COLOR=#333333]Application.ScreenUpdating = False[/COLOR]
[COLOR=#333333]Set ws = Sheets("Invoice")[/COLOR]
[COLOR=#333333]With CreateObject("scripting.dictionary")[/COLOR]
[COLOR=#333333]For Each Cl In ws.Range("D2", ws.Range("D" & Rows.Count).End(xlUp).Offset(-1))[/COLOR]
[COLOR=#333333]If Not .Exists(Cl.Value) And Cl.Value <> "" Then .Add Cl.Value, Nothing[/COLOR]
[COLOR=#333333]Next Cl[/COLOR]
[COLOR=#333333]For Each Ky In .Keys[/COLOR]
[COLOR=#333333]ws.Range("A1").AutoFilter 4, Ky[/COLOR]
[COLOR=#333333]Sheets.Add(, ws).Name = Ky[/COLOR]
[COLOR=#333333]ws.AutoFilter.Range.EntireRow.Copy Sheets(Ky).Range("A1")[/COLOR]
[COLOR=#333333]Sheets(Ky).Columns.AutoFit
[/COLOR]' Next Instruction will add your Unique Number '''''''''''''''''''''''''''''''''''''''''
' You need to determine both the Destination such as cell Z1 and Source such as cell AA1 in Sheets Invoice 
[COLOR=#333333]Sheets(Ky).Range("Z1").value = ws.Range("AA1").value + 1
' Ensure the Number is properly adjusted
[/COLOR][COLOR=#333333]ws.Range("AA1").value + 1 = [/COLOR][COLOR=#333333]ws.Range("AA1").value + 1[/COLOR][COLOR=#333333]
[/COLOR]
[COLOR=#333333]Next Ky[/COLOR]
[COLOR=#333333]End With[/COLOR]
[COLOR=#333333]ws.AutoFilterMode = False[/COLOR]
[COLOR=#333333]ws.Activate[/COLOR]

Hope this will help
 
Upvote 0
James,

it give me an error of "invalid use of property"

Sub Split()
Dim Cl As Range
Dim ws As Worksheet
Dim Ky As Variant

Application.ScreenUpdating = False
Set ws = Sheets("Invoice")
With CreateObject("scripting.dictionary")
For Each Cl In ws.Range("D2", ws.Range("D" & Rows.Count).End(xlUp).Offset(-1))
If Not .Exists(Cl.Value) And Cl.Value <> "" Then .Add Cl.Value, Nothing
Next Cl
For Each Ky In .Keys
ws.Range("A1").AutoFilter 4, Ky
Sheets.Add(, ws).Name = Ky
ws.AutoFilter.Range.EntireRow.Copy Sheets(Ky).Range("A1")
Sheets(Ky).Columns.AutoFit
' Next Instruction will add your Unique Number '''''''''''''''''''''''''''''''''''''''''
' You need to determine both the Destination such as cell Z1 and Source such as cell AA1 in Sheets Invoice
Sheets(Ky).Range("G1").Value = ws.Range("H1").Value + 1
' Ensure the Number is properly adjusted
ws.Range("H1").Value 1 = ws.Range("H1").Value + 1
Next Ky
End With
ws.AutoFilterMode = False
ws.Activate
 
Upvote 0
Hi,

Code:
[COLOR=#333333]Sub Split()[/COLOR]
[COLOR=#333333]Dim Cl As Range[/COLOR]
[COLOR=#333333]Dim ws As Worksheet[/COLOR]
[COLOR=#333333]Dim Ky As Variant[/COLOR]

[COLOR=#333333]Application.ScreenUpdating = False[/COLOR]
[COLOR=#333333]Set ws = Sheets("Invoice")[/COLOR]
[COLOR=#333333]With CreateObject("scripting.dictionary")[/COLOR]
[COLOR=#333333]For Each Cl In ws.Range("D2", ws.Range("D" & Rows.Count).End(xlUp).Offset(-1))[/COLOR]
[COLOR=#333333]If Not .Exists(Cl.Value) And Cl.Value <> "" Then .Add Cl.Value, Nothing[/COLOR]
[COLOR=#333333]Next Cl[/COLOR]
[COLOR=#333333]For Each Ky In .Keys[/COLOR]
[COLOR=#333333]ws.Range("A1").AutoFilter 4, Ky[/COLOR]
[COLOR=#333333]Sheets.Add(, ws).Name = Ky[/COLOR]
[COLOR=#333333]ws.AutoFilter.Range.EntireRow.Copy Sheets(Ky).Range("A1")[/COLOR]
[COLOR=#333333]Sheets(Ky).Columns.AutoFit[/COLOR]
[COLOR=#333333]' Next Instruction will add your Unique Number '''''''''''''''''''''''''''''''''''''''''[/COLOR]
[COLOR=#333333]' You need to determine both the Destination such as cell Z1 and Source such as cell AA1 in Sheets Invoice[/COLOR]
[COLOR=#333333]Sheets(Ky).Range("G1").Value = "[/COLOR][COLOR=#333333]INVOICE-[/COLOR][COLOR=#333333]" & ws.Range("H1").Value + 1[/COLOR]
[COLOR=#333333]' Ensure the Number is properly adjusted[/COLOR]
[COLOR=#333333]ws.Range("H1").Value 1 = ws.Range("H1").Value + 1[/COLOR]
[COLOR=#333333]Next Ky[/COLOR]
[COLOR=#333333]End With[/COLOR]
[COLOR=#333333]ws.AutoFilterMode = False[/COLOR]
[COLOR=#333333]ws.Activate
[/COLOR]End Sub

Hope this will help
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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