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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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