Hi John,
I'm back! Had to take care of some month-end work.
I wanted to confine the macro to just the top section of the worksheet - the Summary section. So, I made a couple of additions to your already awesome code! I want it to stop when it gets to the row with "Grand Total" in column F. So, here's what I have now:
Sub zookeepertx()
Dim i As Long
Dim x As Long
Dim rcell As Range
Dim SL As Range
Set SL = Range("F:F").Find("Grand Total")
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
x = Range("G" & SL.Row - 3)(3)(4).Row
Range("F" & x).Resize(, 4).Cut Range("A" & x)
For i = Range("G" & SL.Row - 3)(3)(1).Row To 13 Step -1
If Range("G" & i).Value = "Total" Then
Range("H" & i).Clear
Range("G" & i + 1).EntireRow.Insert
Rows(i).Font.Bold = True
End If
Next i
For Each numrange In Range("H13:H" & Range("H" & SL.Row - 3)(3)(1).Row).SpecialCells(xlConstants, xlNumbers).Areas
SumAddr = numrange.Address(False, False)
numrange.Offset(numrange.Count, 0).Resize(1, 1).Formula = "=SUBTOTAL(9," & SumAddr & ")"
numrange.Offset(numrange.Count, 0).Resize(1, 2).Formula = "=SUBTOTAL(9," & SumAddr & ")"
c = numrange.Count
Next numrange
NoData:
Range("G13:G" & Range("G" & SL.Row - 3)(3)(1).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
For Each rcell In Range("H13:I" & Range("G" & SL.Row - 3)(3)(1).Row)
rcell.Font.Size = rcell.Offset(-1).Font.Size
rcell.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
If rcell.Offset(, -1).Value = "Total" Then
rcell.Offset(, 2).Value = rcell.Value
rcell.Offset(, 3).Value = rcell.Offset(, 1).Value
End If
Next rcell
With Range("H" & SL.Row - 3)(3)(7)
.Formula = "=SUM(J13:J31)"
.Value = .Value
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End With
With Range("I" & SL.Row - 3)(3)(7)
.Formula = "=SUM(K13:K31)"
.Value = .Value
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End With
Range("A" & SL.Row - 3)(3)(1).Resize(, 4).Cut Range("F" & Range("A" & SL.Row - 3)(3)(1).Row)
Range("J13:K31").ClearContents
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
My only remaining problem is that, near the end of the code, it specifies J13:J31, which is how long the section is on the workbook I posted. But the Summary section is always longer than that, I just never know HOW long it's going to be. I tried replacing "=SUM(J13:J31)" with "=SUM("J13:J" & SL.Row - 3)", but that gives me a Compile error: Expected: end of statement on the J13. So, apparently, I can't use the SL.Row - 3 there or else I've got the syntax wrong. Ideas?
Thank you for your help!
Jenny
Edited: I got the Compile error to go away by using double quotes around J13:J. So, now it recognizes the SL.Row - 3, but it seems to want to back up too many lines. So, on the line that cuts the empty rows, it cuts clear up & includes the last Total row. And the Grand Totals return #NAME, plus the last cells in J and K don't get cleared. I'm not sure what I did wrong, but I'll attach the latest version of the workbook. And, now the end of the code looks like this:
Next rcell
With Range("H" & SL.Row - 3)(3)(7)
.Formula = "=SUM(""J13:J"" & SL.Row - 3)"
.Value = .Value
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End With
With Range("I" & SL.Row - 3)(3)(7)
.Formula = "=SUM(""K13:K"" & SL.Row - 3)"
.Value = .Value
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End With
Range("A" & SL.Row - 3)(3)(1).Resize(, 4).Cut Range("F" & Range("A" & SL.Row - 3)(3)(1).Row)
Range("J13:K" & SL.Row - 3).ClearContents
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Bookmarks