Results 1 to 4 of 4

Macro to Sum Columns based on Headers

Threaded View

  1. #1
    Registered User
    Join Date
    02-27-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Macro to Sum Columns based on Headers

    Okay so I'm fairly new to VBA but I've managed to to get this to partially work. I'm trying to make this sum the Columns and Bold the totals at the bottom of the Column based on the headers which will always be in the first row and start at Column M. I just don't know how to get it to search through the other headers it always stop after summing the first Column. I'm not sure if it has something to do with not making my sum formula variable instead of setting it at Column M.

    I've also included the ActiveWorkbook.Sheets line because I plan to eventually alter it to also repeat this process on a Sheet named Sheet2 after completing Sheet1 but I'm not sure if this line is the way to do it.

    Sub Totals()
    
    Dim end_row_M As Long
    end_row_M = Range("M65536").End(xlUp).Row
    
    Target = "Criteria 1"
    Target2 = "Criteria 2"
    Target3 = "Criteria 3"
    
    Range("M1").Select
    Do Until ActiveCell.Value = ""
    If ActiveCell.Value = Target Or ActiveCell.Value = Target2 Then
    ActiveWorkbook.Sheets("Sheet1").Range("M" & end_row_M + 1).Formula = "=SUM(M2:M" & end_row_M & ")"
    ActiveWorkbook.Sheets("Sheet1").Range("M" & end_row_M + 1).Font.Bold = True And ActiveCell.Offset(0, 1).Activate
    Else
    ActiveCell.Offset(0, 1).Activate
    End If
    Loop
    
    End Sub
    Last edited by Jluc; 03-24-2011 at 02:37 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1