VB line for UserForm: Unique Identifier in Column A

Yecart77

New Member
Joined
Nov 8, 2022
Messages
20
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
Hi Experts,
I'm really loving learning Excel and VB but need some input from the experts. Using 365 at home but this file will be in Excel 2016.

sh.Range("A" & last_Row + 1).Value = "=Row()-1"

The formula above puts numbers 1,2,3,etc in Cells A2, A3, A4 of the form.

I have this formula that works great in a normal Excel worksheet.

="ABCD-"&""&TEXT(ROW()-ROW($A$1),"0000")&"/"&2024

The outcome is:
A1: Heading
A2: ABCD-0001/2024
A3: ABCD-0002/2024
A4: ABCD-0003/2024 etc etc

When I replace red text with the purple text and add " " marks each end it returns an error.

How do I correct it? I am wanting the outcome ABCD-0001/2024 etc.

I have attached a copy of the VBA from the 'Add' button.

Thank you for any ideas in advance. :-)
 

Attachments

  • VBA.png
    VBA.png
    29.8 KB · Views: 11

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try
VBA Code:
sh.Range("A" & last_Row + 1).Formula= "=""ABCD-""&""""&TEXT(ROW()-ROW(R1C1),""0000"")&""/""&2024"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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