+ Reply to Thread
Results 1 to 8 of 8

Automatic select of Total SUM column

Hybrid View

  1. #1
    Registered User
    Join Date
    09-24-2022
    Location
    London
    MS-Off Ver
    Microsoft Office 2019
    Posts
    70

    Automatic select of Total SUM column

    Hello - I have tried the sum when the Total SUM column is always is in F column in different sheets with the help of code but what if we have sheets where the Total SUM is in different column in different sheets ?
    How to select such columns , something which searches the header for the term "Total SUM and it should be dynamic ?

    Attached file
    Attached Files Attached Files

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Automatic select of Total SUM column

    Hi,

    Does this help you?

    Sub Automate_Sum()
    Dim ws As Worksheet
    Dim iLastColumn As Integer, iLastRow As Integer
    
    For Each ws In ThisWorkbook.Worksheets
    
    With ws
    
    iLastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    iLastColumn = Application.WorksheetFunction.Match("Total SUM", .Rows(1))
    
    .Cells(2, iLastColumn).Formula = "=SUM(C2:" & Cells(2, iLastColumn - 1).Address(0, 0) & ")"
    .Cells(2, iLastColumn).AutoFill Destination:=Range(.Cells(2, iLastColumn), .Cells(iLastRow, iLastColumn))
    
    End With
    
    Next ws
    
    End Sub
    Last edited by sweep; 10-13-2022 at 10:59 AM.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatic select of Total SUM column

    Sub J3v16()
    Dim ws As Worksheet
    For Each ws In Sheets
        With ws.Cells(1).CurrentRegion
            With .Offset(1).Resize(.Rows.Count - 1).Columns(.Columns.Count)
                .Formula = "=SUM(C2:" & .Cells(1, .Columns.Count - 1).Address(0, 0) & ")"
            End With
            .Cells(.Rows.Count + 1, .Columns.Count).Formula = "=SUM(" & .Cells(2, .Columns.Count).Address(0, 0) & ":" & .Cells(.Rows.Count, .Columns.Count).Address(0, 0) & ")"
        End With
    Next ws
    End Sub
    Last edited by Sintek; 10-13-2022 at 01:09 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    09-24-2022
    Location
    London
    MS-Off Ver
    Microsoft Office 2019
    Posts
    70

    Re: Automatic select of Total SUM column

    Thank you so much.
    Sir what if i want of total in Total SUM column in all sheets and more dynamics ?

    Like below screenshot :Attachment 800479

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatic select of Total SUM column

    Invalid attachment, but am guessing you want to total the SumTotal Column...See amended red snippet above...

  6. #6
    Registered User
    Join Date
    09-24-2022
    Location
    London
    MS-Off Ver
    Microsoft Office 2019
    Posts
    70

    Re: Automatic select of Total SUM column

    Attached file with red arrow autosum which i want
    Attached Files Attached Files

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatic select of Total SUM column

    Yep...red snippet added in post 3 does that...

  8. #8
    Registered User
    Join Date
    09-24-2022
    Location
    London
    MS-Off Ver
    Microsoft Office 2019
    Posts
    70

    Re: Automatic select of Total SUM column

    Oh.. I am sorry.. I did not refresh the page.
    Thank you so much Sir.
    It is very helpful.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Vba makro sort and automatic sum sub total
    By daboho in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2016, 07:05 PM
  2. Select Case Loop to highlight grand total column
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-05-2016, 09:57 AM
  3. [SOLVED] select value less than 50 automatic
    By mazan2010 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-07-2016, 09:37 AM
  4. [SOLVED] Select Automatic Report Filter in Pivot where Filter exist in Data table else select Blank
    By vinaynaran in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-02-2016, 08:47 AM
  5. Automatic total number of weeks
    By khank in forum Excel General
    Replies: 3
    Last Post: 12-31-2010, 12:13 AM
  6. How do I set up an automatic column select
    By Snoopy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-25-2006, 04:55 AM
  7. Automatic total of more than one invoices
    By Dr.H.Subramanian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2005, 05:06 AM

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