Update sequence for any change

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Update sequence for any change

Post by YasserKhalil »

Hello everyone
In column A, I have values like that AO.1, AO.2, AO.3 and so on
Is there a way to update the numbers after the dot when making any changes in column A?
I mean if a new row is inserted in between data, I need to renumbering the data to make the numbers after the dot in sequence. The same when deleting any row

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update sequence for any change

Post by HansV »

Let's say the values begin in A2.
Enter the formula ="AO."&ROW()-1 in A2 and fill down.
When you delete a row, the numbering will be updated automatically.
When you insert a row, you only need to fill down from the cell above in column A.
If you wish, you can create a macro

Code: Select all

Sub InsertRow()
    Application.CutCopyMode = False
    ActiveCell.EntireRow.Insert
    ActiveCell.Offset(-1).Resize(2).FillDown
End Sub
and assign it to a custom Quick Access Toolbar button and/or a custom keyboard shortcut, for example Ctrl+Shift+I
Best wishes,
Hans

User avatar
DocAElstein
4StarLounger
Posts: 584
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Update sequence for any change

Post by DocAElstein »

I was thinking maybe you might have different words , like
amd.1
fffff.2
thtth.3
slkhfslkfh.4


We can start then with a formula that remakes those words and numbers
=LEFT(A1,FIND(".",A1))&ROW(A1)

I think we should know what beautiful things we can do in Evaluate(“ “) with that

Code: Select all

 Sub RowRow() ' https://eileenslounge.com/viewtopic.php?f=30&t=37713
Dim vTemp As Variant
                       '=LEFT(A1,FIND(".",A1))&ROW(A1)
 Let vTemp = Evaluate("=LEFT(A1,FIND(""."",A1))&ROW(A1)")
 Let vTemp = Evaluate("=LEFT(A1:A3,FIND(""."",A1:A3))&ROW(A1:A3)")
 Let vTemp = Evaluate("=LEFT(A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & ",FIND(""."",A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & "))&ROW(A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & ")")

 Let Range("A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & "").Value = vTemp

 Let Range("A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & "").Value = Evaluate("=LEFT(A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & ",FIND(""."",A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & "))&ROW(A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & ")")
End Sub 
Then some variation of that in an event macro, something like

Code: Select all

 Private Sub Worksheet_Change(ByVal Target As Range)
 Let Application.EnableEvents = False
 Let Range("A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & "").Value = Evaluate("=LEFT(A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & ",FIND(""."",A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & "))&ROW(A1:A" & Range("A" & Rows.Count & "").End(xlUp).Row & ")")
 Let Application.EnableEvents = True
End Sub 
You do not have the required permissions to view the files attached to this post.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Update sequence for any change

Post by YasserKhalil »

Thank you very much for your great support both of you.
Best Regards