Is there a way to include adding a series of equations to a worksheet in VBA for a range of cells that will change from day to day. The equation is simple, just =O2-M2 and then dragged down the list, so O3-M3, Etc. However how many cells will be in the column will change from day to day. I currently have it set out to about 100 more cells than we have had as a recent max, but I would definately prefer for it to simply take into account how many cells there actually are in the adjoining row.
Thanks for any help that you guys might come up with. I did include the code below, I know it is a little garbled, duct taped it together from the macro recorder.
Sub Macro2()
'
' Macro2 Macro
'
'
Windows("PV_54.xls").Activate
Columns("P:P").Select
Selection.Insert Shift:=xlToRight
Range("P2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-3]"
Range("P2").Select
Selection.AutoFill Destination:=Range("P2:P400"), Type:=xlFillDefault
Range("P2:P400").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
Columns("V:V").Select
Selection.Insert Shift:=xlToRight
Range("V2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
Range("V2").Select
Selection.AutoFill Destination:=Range("V2:V400"), Type:=xlFillDefault
Range("V2:V400").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 17
Columns("AF:AF").Select
Selection.Insert Shift:=xlToRight
Range("AF2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
Range("AF2").Select
Selection.AutoFill Destination:=Range("AF2:AF400"), Type:=xlFillDefault
Range("AF2:AF400").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Rows("1:1").Select
Range("Q1").Activate
Selection.AutoFilter
Range("D4").Select
Windows("PV_54.xls").Activate
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
Selection.AutoFilter Field:=22, Criteria1:="<>0", Operator:=xlAnd
Windows("Macro holder for Recon.xls").Activate
Range("H12").Select
End Sub
Bookmarks