Macro for pasting a sequence of numbers to many rows in one column

FreshDK

New Member
Joined
Feb 21, 2017
Messages
14
Hi,

I have a sheet with 10.000 rows of data:

aaa111
aaa222
bbb111
ccc111
ccc222
ccc333
......

Sometimes I need to filter and sort the rows to view only certain rows in a specific order. But I need index numbers to be able to get back to the original order, so i do like this:

1aaa111
2aaa222
3bbb111
4ccc111
5ccc222
6ccc333
...10.000......

My problem is when I add new rows to the sheet, it is never in the bottom, but always at a specific place. Then I mess up the index numbers because they need to be "dead" and not generated by a formula not to mess up when i do filter and sorting:

1aaa111
2aaa222
3bbb111
bbb222
4ccc111
5ccc222
6ccc333
...10.000......


Right now I have this neat macro to add line below (with formulas) when i double click inside my sheet:

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby Extendoffice 20160725
    Cancel = True
    Target.Offset(1).EntireRow.Insert
    Target.EntireRow.Copy Target.Offset(1).EntireRow
    On Error Resume Next
    Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
End Sub

My wish is to add to this macro so that it "updates" my index numbers (pastes a new sequence of numbers from A1 to A100000) after inserting a new row. Right now it's very fragile if i don't remember to update index numbers before the occasional filter and sorting, then i cannot go back without messing up my dataset.

I have tried to google, but I cannot seem to find what I'm looking for.

Br.

FreshDK
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I found a workaround macro to copy a range from a different sheet. It works but it is not elegant!
 
Upvote 0

Forum statistics

Threads
1,215,746
Messages
6,126,641
Members
449,325
Latest member
Hardey6ix

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