vba InsertUserName

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Good Day All,

I'm trying to create a sub that adds the data upon the username with its date and time onto a sheets cell.

VBA Code:
Sub InsertUserName()

Application.Goto Worksheets(2).Range("A1"), True

Range("A1").EntireRow.Insert

ActiveCell.Value = Environ("username") & " - " & Now()
    
End Sub

However, I do not want it to shift the entire row to move down when the sub has been run more than once.

For example, Before run:

Untitled before .png



After run:

Untitled after .png


Where I'd like theoretically all other columns data and rows to not be moved when the sub is run and only for it to insert and move data down for Column A.

Please let me know, if you have any suggestions.

Thank you!
pinaceous
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try this. I changed your code slightly.
VBA Code:
Sub InsertUserName()

Application.Goto Worksheets(2).Range("A1"), True

Range("A1").Insert(xlShiftDown)

ActiveCell.Value = Environ("username") & " - " & Now()
    
End Sub
 
Upvote 0
Try this. I changed your code slightly.
VBA Code:
Sub InsertUserName()

Application.Goto Worksheets(2).Range("A1"), True

Range("A1").Insert(xlShiftDown)

ActiveCell.Value = Environ("username") & " - " & Now()
   
End Sub
*Skyybot!

Thank you so much!

That worked perfectly!

R/
pinaceous
 
Upvote 0

Forum statistics

Threads
1,215,711
Messages
6,126,401
Members
449,312
Latest member
sweetfriend9

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