I'm not too versed in Excel VBA. I have a xls where I need to insert a column (E) and input formula "=right(D2,4)" and then copy that for all the rows that contain data. I do this each week and the number of rows changes. Below is what I have and been manually going in and changing the last number of the range. How can I automate it so I don't have to?
Sub Assignment_Tracker()
'
' Assignment_Tracker Macro
'
Rows("1:2").Select
Range("A2").Activate
Selection.Delete Shift:=xlUp
Cells.Select
Cells.EntireColumn.AutoFit
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("E1").Select
ActiveCell.FormulaR1C1 = "Last_4"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1], 4)"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E343"), Type:=xlFillCopy
Range("E2:E343").Select
Range("A1").Select
End Sub
Sub Assignment_Tracker()
'
' Assignment_Tracker Macro
'
Rows("1:2").Select
Range("A2").Activate
Selection.Delete Shift:=xlUp
Cells.Select
Cells.EntireColumn.AutoFit
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("E1").Select
ActiveCell.FormulaR1C1 = "Last_4"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1], 4)"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E343"), Type:=xlFillCopy
Range("E2:E343").Select
Range("A1").Select
End Sub