Add a new row at table bottom

Hellyworld

New Member
Joined
May 3, 2017
Messages
6
Hi,

I need your help with a code that will add a new row at the bottom of the table. The code is working but i need to add on this new row in "H" column the Application.UserName and on "F" column the Date.

This is my code until now:

Code:
    Sub Insert_New_Rows()    Dim Lr As Integer
     
    Lr = Range("B" & Rows.Count).End(xlUp).Row 'Searching last row in column B
    Rows(Lr + 1).Insert Shift:=xlDown 'Inserting new row
    Cells(Lr + 1, "B") = Cells(Lr, "B") + 1 'Adding a sequential number
    Rows(Lr).Copy 'Copying format of last row
    Rows(Lr + 1).PasteSpecial Paste:=xlPasteFormats 'Pasting format to new row
    Application.CutCopyMode = False 'Deactivating copy mode
End Sub


For more details please do not hesitate to contact me!

Best regards,
Hellyworld
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,

I am back and I have the solution!

If i had waited few more minutes, I would not have had to waste your time.
This is my solution:

Code:
Sub Insert_New_Rows()    Dim Lr As Integer
     
    Lr = Range("B" & Rows.Count).End(xlUp).Row 'Searching last row in column B
    Rows(Lr + 1).Insert Shift:=xlDown 'Inserting new row
    Cells(Lr + 1, "B") = Cells(Lr, "B") + 1 'Adding a sequential number
    Rows(Lr).Copy 'Copying format of last row
    Rows(Lr + 1).PasteSpecial Paste:=xlPasteFormats 'Pasting format to new row
    Application.CutCopyMode = False 'Deactivating copy mode
    Range("H" & Lr + 1).Value = Application.UserName
    Range("F" & Lr + 1).Value = Date
    
End Sub

Maybe will help you too!

Have a nice day,
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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