Ask Experts Questions for FREE Help !
Ask
    adalton's Avatar
    adalton Posts: 22, Reputation: 1
    New Member
     
    #1

    Jun 13, 2009, 08:08 PM
    Summing Dynamic Cells
    Sorry for all the dumb questions :( I'm still getting used to excel.

    I need to go down a column and sum some cells before it. However depending on the column this may change.

    I tried using the Sum function but that requires the values to be set.

    In a column the sum cells will be the same... Ie go down G sum values from A-F, however the next column may be J and it needs to sum values from H & I.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Jun 13, 2009, 10:24 PM

    Sorry, the question provides no meaningful information for suggesting a formula or a macro. When something is this (apparently) difficult to explain, don't. Show us.

    So mockup a sample workbook showing the dilemma and your desired results, point out where the results came from if not obvious in your sample data. If the results change with various scenarios, demonstrate multiple scenarios until every possible need is covered.

    Be sure to reread your sheet from the perspective of "I didn't write this, does it make sense what I've written"?

    Then click GO ADVANCED and use the paperclip icon to post up your workbook.
    adalton's Avatar
    adalton Posts: 22, Reputation: 1
    New Member
     
    #3

    Jun 14, 2009, 11:06 AM
    So right now it goes through until it finds a SUM column. I want it to SUM all the columns up until the last SUM column.

    The bold is what I want the macro to do.
    adalton's Avatar
    adalton Posts: 22, Reputation: 1
    New Member
     
    #4

    Jun 14, 2009, 11:08 AM
    Sorry here's the sample.
    Attached Files
  1. File Type: xls example.xls (19.5 KB, 159 views)
  2. JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #5

    Jun 14, 2009, 03:09 PM

    Here's a macro to do what you wish. I took out the row 1 labels since they were redundant. Just put your data in row1.
    Code:
    Option Explicit
    
    Sub AddRowTotals()
    Dim LR As Long, FC As Long, LC As Long, i As Long
    LR = Cells(Rows.Count, "A").End(xlUp).Row
    LC = Cells(1, Columns.Count).End(xlToLeft).Column + 1
    FC = 1
    
    'Determine columns to be summed, insert formula
    For i = 1 To LC
        If Cells(2, i) = "" Then
            If Cells(2, i - 1).HasFormula Then Exit Sub
            With Range(Cells(1, i), Cells(LR, i))
                .FormulaR1C1 = "=SUM(RC" & FC & ":RC" & LC - 1 & ")"
                .Font.Bold = True
            End With
            
        ElseIf Cells(2, i).HasFormula = True And IsNumeric(Cells(2, i + 1)) Then
            FC = i + 1
        End If
        
    Next i
    
    End Sub
    Attached Files
  3. File Type: xls AddRowTotals.xls (37.0 KB, 153 views)
  4. ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #6

    Jun 14, 2009, 03:21 PM

    I'm not sure if a macro is necessary here. I think your problem is that if you use the AUTOSUM feature it will automatically try to sum all the contiguous columns, So if use the
    AutoSum in Column G, it will sum A-F. But if you only want it to sum D-F, you can manually adjust the formula or type I in:

    =Sum(D2:F2)
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #7

    Jun 14, 2009, 05:31 PM

    I thought the same thing, then realized he just wants the sums added quickly/easily without having to do any of the figuring out each time. Understandable.
    adalton's Avatar
    adalton Posts: 22, Reputation: 1
    New Member
     
    #8

    Jun 14, 2009, 08:34 PM
    Thanks. Your code worked beautifully JBeaucaire

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

'too dynamic'? [ 2 Answers ]

I'm 21 and never had a serious boyfriend(I never really stayed with a guy for longer than a month and never had sex with anyone). I have always been a busy girl, never had that much free time, and it never bothered me before. But it does now, cause I'm in college and have more free time, and also...

VB6- Access2003 summing data onClick [ 7 Answers ]

I have a form in Access2003 called Daily_Log The form is tied to the Daily_Log table. On the form, I have a text box called Log_Date. I also have a text box called Count_Logged with a button next to it called cmdGetLog What I am trying to do is this: When a user enters in a date in...

Dynamic IP [ 1 Answers ]

Hi all the Experts,

Clicking differnet cells and it selecting all cells [ 2 Answers ]

Just wondered if anyone knew what I did to get ms excel to select all cells from A1 to what ever cell I clicked on. Thought it was sticky keys but it was turned off. Clicked left mouse button and it moved cells then when I clicked other cells it started using that as a new ref point and selecting...


View more questions Search