stirlingmw1
Board Regular
- Joined
- Jun 17, 2016
- Messages
- 53
- Office Version
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Morning All
I am trying to add the formula "=Sum(from:to)" into a column within my worksheet. I can get the formula to work if I use column letters but i want to be able to add LastColumn into the formula.
the code I am using at present that works is:
what I want to do is use the formula =Sum(C" & ActiveCell.Row + 1 & , but where ":Y" is the column being used as the final column I want to use LastColumn & ActiveCell.Row + 1 & ")". but this final change doesnt work.
I have
The reason I want the LastColumn referenced is that the formula could move left or right in the worksheet and I would like the formula to adjust also. What am i doing wrong?
Regards
Steve
I am trying to add the formula "=Sum(from:to)" into a column within my worksheet. I can get the formula to work if I use column letters but i want to be able to add LastColumn into the formula.
the code I am using at present that works is:
VBA Code:
Sheets("Minor_22-23").Range(Cells(3, LastColumn), Cells(lastrow, LastColumn)).Formula = "=Sum(C" & ActiveCell.Row + 1 & ":Y" & ActiveCell.Row + 1 & ")"
what I want to do is use the formula =Sum(C" & ActiveCell.Row + 1 & , but where ":Y" is the column being used as the final column I want to use LastColumn & ActiveCell.Row + 1 & ")". but this final change doesnt work.
I have
VBA Code:
Dim LastColumn as Long
LastColumn = Sheets("Minor_22-23").Cells(1, Sheets("Minor_22-23").Columns.Count).End(xlToLeft).Column
The reason I want the LastColumn referenced is that the formula could move left or right in the worksheet and I would like the formula to adjust also. What am i doing wrong?
Regards
Steve