Automatically number newly added Rows (Insert Shift:=xlDown)

TomCooper88

New Member
Joined
Aug 8, 2013
Messages
2
Hello People!

I hope someone here can help me... I have made a macro that copies a row into a new sheet:

Sheets("Datasheet").Select
Range("A2").Select
ActiveCell.EntireRow.Insert Shift:=xlDown

Sheets("MailMerge").Select
Range("A7:G7").Select
Selection.Copy
Sheets("Datasheet").Select
Range("A2:G2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

What I want now, is that everytime a new row is copied in the second row (first row are names),
The cell A2 to get a number that is +1 to the last one. So starting with 1, the second copied row would be 2, etc etc...

I hope there's somebody out there who knows the answer!

Kind Regards,
Tom
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi

Try :-
Code:
Dim TempA2 As Long
Sheets("Datasheet").Select
Range("A2").Select
TempA2 =Range("A2").Value

ActiveCell.EntireRow.Insert Shift:=xlDown

Range("MailMerge!A7:G7").Copy


Range("A2:G2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A2").Value = TempA2 + 1

hth
 
Upvote 0
Hi Tom

Thanks for the feedback.

You could reduce your code to the following by removing the "Selects" :-
Code:
Range("Datasheet!A2").EntireRow.Insert Shift:=xlDown

Range("MailMerge!A7:G7").Copy

Range("Datasheet!A2:G2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range("Datasheet!A2").Value = Range("Datasheet!A3").Value  + 1

Pleased to have helped solve your problem.

Good luck with your project.
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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