Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Sub DoTasks() Dim cell As Range Dim total As Long Dim rows_in_col As Long Dim header As Range 'Find cells in header If Range("A4") = "" Then 'May only be one cell in header Set header = Range("A4") Else Set header = Range(Range("A4"), Range("A4").End(xlToRight)) End If 'Find the max row For Each cell In header rows_in_col = Range(cell, cell.End(xlDown)).Count If rows_in_col > total Then total = rows_in_col End If Next cell 'Add the sum column two rows below max For Each cell In header If cell.Column = 11 Or cell.Column = 12 Then Cells(cell.Row + total + 1, cell.Column).Formula = "=@subtotal(9," & Range(cell, cell.End(xlDown)).Address & ")" End If Next cell 'Same command as double clicking the border. Range("A:M").EntireColumn.Autofit Cells(header.Row + total + 1, 1).Activate End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.