Hello,
I have been struggling with finding the last used column and pasting a formula in the same row to the last column. Here is what I have used and it isn't working.:
Sub Subtotal()
Dim LastRow As Long
Dim LastCol As Long
Dim lastcell As String
'Define Variables
LastRow = Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.UsedRange.Select
LastCol = Range("A" & Columns.Count).End(xlToLeft).Column
lastcell = ActiveCell.SpecialCells(xlLastCell).Address
iLastColumn = Range("A7").End(xlToRight).Row
a = Cells(7, Columns.Count).End(xlToLeft).Column
Range("R1").Select
Selection.NumberFormat = "#,##0"
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[2]C:R[" & LastRow & "]C)"
Range("R1").Select
Selection.Copy
'it errors out at next line, I just want to take the ActiveCell.Formula above and copy it all the way to the last column used.
Range("R1:" & iLastColumn).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Any thoughts?
Many thanks!
Matt
Bookmarks