Hi There -
I have the following repetitive code which I use to calculate differences between various columns. Any ideas how I can simply the code or setup a function and call it within my code?
I have the following repetitive code which I use to calculate differences between various columns. Any ideas how I can simply the code or setup a function and call it within my code?
Code:
'Add Column and Difference
Range("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveSheet.Range("E3").Select
Selection.FormulaR1C1 = "Difference"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A25000")
Range("F:F").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
'Add Column and Difference
Range("I:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveSheet.Range("I3").Select
Selection.FormulaR1C1 = "Difference"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A25000")
Range("J:J").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Last edited by a moderator: