Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts

    Using Indirect Function in Sum Formula

    I have a sum formula referring to a cells to add data on various sheets for eg =sum(Oct:Mar!B6) ,=sum(Oct:Mar!B7) etc

    I would like to use an indirect formula to refer to a month name from a drop down list so that the formula to be changed immediate for eg If I want to calculate a value from Oct to Dec , I would select Dec from the Drop down list and the formula would change to = sum(Oct:Dec!B6)
    The starting point would always be Oct for eg = sum(Oct: ....)
    Last edited by RetiredGeek; 2015-04-28 at 16:02. Reason: Added NoParse tags

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Howard,

    The Indirect function does NOT support 3D (multi-sheet range) references.

    I've tried a UDF w/o success. What you may want to try is adding a hidden sheet at the end and then just insert new month before the hidden sheet. Then use a formula with that sheet name as the end and you don't even need the dropdown
    =SUM(Oct:EndSht!B6)

    Test File: HowardC3dSum.xlsx

    HTH
    Last edited by RetiredGeek; 2015-04-29 at 09:07.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts
    Hi RG

    Thanks for your input


    I cannot open up your attachment. I comes up with Invalid attachment specified.

  4. #4
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,638
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Howard,

    The following code will take the selected value of a combobox and place it in the formula as you described. The formula is in cell A5.

    HTH,
    Maud

    Code:
    Private Sub ComboBox1_Change()
    Range("A5").Formula = "=sum(Oct:" & ComboBox1 & "!B7)"
    End Sub
    HC2.png
    Attached Files Attached Files

  5. #5
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts
    Hi Maud

    This is perfect

    I have not set up a combobox for a very long time so a bit rusty. Please explain to me how to set up the combobox in your example and linking to the months

    Howard

  6. #6
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,638
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Howard,

    The months are on a hidden spreadsheet (xlSheetVeryHidden) called "settings" in the range A2:A12. Note the list range in the properties window for the combobox

    HC3.png

  7. #7
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts
    Thanks Maud

    It has now come back to me on how to set this up. I have set up the months on the same spreadsheet (called months) and linked it to the combo box and changed the properties in listfillrange to months!A1:A12

    I have amended your code to account for other formulas for eg



    Code:
     Private Sub ComboBox1_Change()
    Range("A5").Formula = "=sum(Oct:" & ComboBox1 & "!B7)"
    Range("A6").Formula = "=sum(Oct:" & ComboBox1 & "!B8)"
    End Sub

  8. #8
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts
    Hi Maud

    I have set up code to change the value based on the month selection which works fine, but have had to manually amend the cell references-see below

    Is there a way to incement the cell reference by 1 in the code?


    Code:
     Private Sub ComboBox1_Change()
    Range("B4").Formula = "=sum(Oct:" & ComboBox1 & "!B4)"
    Range("B5").Formula = "=sum(Oct:" & ComboBox1 & "!B5)"
    Range("B6").Formula = "=sum(Oct:" & ComboBox1 & "!B6)"
    Range("B7").Formula = "=sum(Oct:" & ComboBox1 & "!B7)"
    Range("B8").Formula = "=sum(Oct:" & ComboBox1 & "!B8)"
    Range("B9").Formula = "=sum(Oct:" & ComboBox1 & "!B9)"
    Range("B10").Formula = "=sum(Oct:" & ComboBox1 & "!B10)"
    Range("B11").Formula = "=sum(Oct:" & ComboBox1 & "!B11)"
    Range("B12").Formula = "=sum(Oct:" & ComboBox1 & "!B12)"
    Range("B13").Formula = "=sum(Oct:" & ComboBox1 & "!B13)"
    Range("B12").Formula = "=sum(Oct:" & ComboBox1 & "!B12)"
    Range("B13").Formula = "=sum(Oct:" & ComboBox1 & "!B13)"
    Range("B14").Formula = "=sum(Oct:" & ComboBox1 & "!B14)"
    Range("B15").Formula = "=sum(Oct:" & ComboBox1 & "!B15)"
    Range("B16").Formula = "=sum(Oct:" & ComboBox1 & "!B16)"
    Range("B17").Formula = "=sum(Oct:" & ComboBox1 & "!B17)"
    
    Range("B18").Formula = "=sum(Oct:" & ComboBox1 & "!B18)"
    Range("B19").Formula = "=sum(Oct:" & ComboBox1 & "!B19)"
    Range("B20").Formula = "=sum(Oct:" & ComboBox1 & "!B20)"
    
    
    
    End Sub

  9. #9
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,826
    Thanks
    136
    Thanked 482 Times in 459 Posts
    HI Howard

    ..you have repeated it twice for B12 and B13!

    Try this shorter method:
    Code:
    Private Sub ComboBox1_Change()
    [b4] = "=sum(Oct:" & ComboBox1 & "!B4)"
    temp = "b5:b20"
    [b4].Copy Range(temp)
    ActiveCell.Select
    End Sub
    zeddy

  10. #10
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,638
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Howard,

    Do you may want the formulas in column A rather than column B as your formulas suggest? Aside from Zeddy's code, this will also work.

    Code:
    Private Sub ComboBox1_Change()
        For I = 4 To 20
            Cells(I, 1).Formula = "=sum(Oct:" & ComboBox1.Value & "!B" & I & ")"
        Next I
    End Sub
    Change to Cells(I, 2).Formula = "=sum(Oct:" & ComboBox1.Value & "!B" & I & ")" if you want the formulas placed in column B instead
    Last edited by Maudibe; 2015-04-29 at 05:44.

  11. #11
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Howard,

    I've fixed the attachment in post #2, sorry about that! HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  12. #12
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts
    Thanks Zeddy & Madibe for your input

    Te code works perfectly

    Maud the formulas must be in Column B.

  13. #13
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,420
    Thanks
    124
    Thanked 5 Times in 5 Posts
    Hi RG

    No problem

  14. #14
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    FWIW - and note I do not recommend this as a solution, it's just for information - you can make INDIRECT work with a 3D reference in this situation. See attached.
    Attached Files Attached Files
    Regards,
    Rory

    Microsoft MVP - Excel

  15. The Following User Says Thank You to rory For This Useful Post:

    RetiredGeek (2015-04-30)

  16. #15
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Rory,

    Tricky...Very Tricky!

    You da' MAN!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Page 1 of 2 12 LastLast

Posting Permissions

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