tsroque
Board Regular
- Joined
- Jan 19, 2007
- Messages
- 127
- Office Version
- 365
Hey Guys -
This VBA code works, but just wondering if there is a better way to write it.
PURPOSE/GOAL: User can add additional time to a day on a timesheet. Example: Employee works two shifts. Timesheet has In/Out/In/Out columns (4) so when they clock in more than 2x, we have to insert an additional row. The users are not Excel experts so I need to make inserting a row as user-friendly as possible.
Thank you!
This VBA code works, but just wondering if there is a better way to write it.
PURPOSE/GOAL: User can add additional time to a day on a timesheet. Example: Employee works two shifts. Timesheet has In/Out/In/Out columns (4) so when they clock in more than 2x, we have to insert an additional row. The users are not Excel experts so I need to make inserting a row as user-friendly as possible.
Code:
Sub AddRow()
'Inserts and Copies a Row Below a Selected Cell with Same Formatting
With ActiveCell
.EntireRow.Copy
.EntireRow.Insert
End With
Application.CutCopyMode = False
' Clear Cells in Range D:G
ActiveCell.Offset(1, 2).Select
ActiveCell = Null
ActiveCell.Offset(0, 1).Select
ActiveCell = Null
ActiveCell.Offset(0, 1).Select
ActiveCell = Null
ActiveCell.Offset(0, 1).Select
ActiveCell = Null
' Clear Cells in Range P:Q
ActiveCell.Offset(0, 9).Select
ActiveCell = Null
ActiveCell.Offset(0, 1).Select
ActiveCell = Null
' Clear Cell, Copy Above Cell and Paste VALUE to Cell Below
ActiveCell.Offset(0, -15).Select
ActiveCell = Null
ActiveCell.Offset(-1, 0).Select
ActiveCell.Copy
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
Thank you!