VBA for Unique IDs

dannyok90

Board Regular
Joined
Aug 30, 2016
Messages
115
Hi all, I've scoured the forum for a solution to this. I know there are various threads that are related but either my VBA skills aren't quite good enough or they don't quite match my requirements.

basally I have the following script:

Code:
Sub AddRow()
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ActiveSheet
Application.ScreenUpdating = False
LastRow = sht.Range("A:A").CurrentRegion.Rows.Count
Range("Sheet1!A26").EntireRow.Copy
Range("A" & LastRow + 1).EntireRow.Insert
Range("A" & LastRow + 1).EntireRow.Hidden = False
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

it simply adds a new row to my sheet by copying a template row from one sheet and pasting it in another. after the paste id like to add a unique id with a prefix in the first cell. probably XYZ/ddmmyyhhmmss. So if I delete an entry later, the id below as the cells move up will remain the same.

Thanks!
Dan
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi there.

Add the red line of code below:
Code:
Sub AddRow()
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ActiveSheet
Application.ScreenUpdating = False
LastRow = sht.Range("A:A").CurrentRegion.Rows.Count
Range("Sheet1!A26").EntireRow.Copy
Range("A" & LastRow + 1).EntireRow.Insert
Range("A" & LastRow + 1).EntireRow.Hidden = False
[COLOR=#ff0000]Range("A" & lastrow + 1).Value = "XYZ/" & Format(Date, "ddmmyy") & Format(Time, "hhmmss")[/COLOR]
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,923
Messages
6,175,401
Members
452,640
Latest member
steveridge

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