I'm trying to use VBA to insert a new row and then create a reference using the date in the format yyyymmdd followed by a hyphen and then 1.
So for example, today I would like the output to read 20251117-1. I have used the code below, but this causes two problems.
The user needs to have cell A7 selected otherwise the -1 outputs in the selected cell
When A7 is selected adding the "-1" changes the way that the date displays, so for today it changes the output to 17/11/2025-1
Sub Reference()
Rows(7).Insert
Range("A7") = Date
Range("A7").NumberFormat = "yyyymmdd"
ActiveCell.Value = ActiveCell.Value & "-1"
End Sub