sorry, I am new to this. When I said that it bugged out, I meant that the
code stopped working at that point and went to the debugger. Lastrow was
what was highlighted with a message about a compile error. What I want to do
is to create a worksheet with a variable number of lines with a total at the
end. It was working fine until I tried to add the "Total at month end" That
cell was empty. so i added the code just above my code for my totals. If i
take that part out it works ok. Here is the whole code
Sub CreateEndingWorkbook()
'
'
'Delete Outstanding worksheet
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("Outstanding").Delete
On Error GoTo 0
Application.DisplayAlerts = True
'Create new Outstanding worksheet with most recent data
Sheets("TotalForMonth").Select
Sheets("TotalForMonth").Copy Before:=Sheets(1)
Sheets("TotalForMonth (2)").Select
Sheets("TotalForMonth (2)").Name = "Outstanding"
Application.Run "PERSONAL.XLS!DeleteCleared" '<<<< see below
'Add label for last row
LastRow = Range("A65536").End(xlUp).Row + 1
Sheet("Outstanding").Range("A" & LastRow).Value = "Total Outstanding at
Month End"
'Add totals to report
Cells(1, 1).End(xlDown).Offset(1, 0).Range( _
"F2,H2,I2").FormulaR1C1 = "=Sum(R2C:R[-1]C)"
End Sub
Sub DeleteCleared()
'will delete a rows that have been resolved
Dim LastRow As Long
Dim Row As Long
LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For Row = LastRow To 1 Step -1
If Cells(Row, "G") = "R" Then
Rows(Row).Delete
End If
Next Row
End Sub
Jim Thomlinson said:
The code you have may or may not do what you want depending on which sheet is
the active sheet... Try using a range object to hold the spot where you want
to make the changes...
dim rng as range
set rng = sheet1.cells(rows.count, "a").end(xlup).offset(1,0)
rng.value = "Total Outstanding at Month End"
rng.offset(0,1).FormulaR1C1 = "=Sum(R2C:R[-1]C)" 'not sure what you want here
--
HTH...
Jim Thomlinson
:
my code works fine with the total line, but when I added the label in column
A it bugged out. What is wrong with code?
'Add label for last row
lastrow = Range("A65536").End(xlUp).Row
lastrow = lastrow + 1
Sheet1.Range("A" & lastrow) = "Total Outstanding at Month End"
'Add totals to report
Cells(1, 1).End(xlDown).Offset(1, 0).Range( _
"F2,H2,I2").FormulaR1C1 = "=Sum(R2C:R[-1]C)"
End Sub