Use VBA Calculated Sum in Another Formula

rgarrity

New Member
Joined
Mar 3, 2017
Messages
20
I have a worksheet where the rows are dynamic. in several columns, I have VBA to calculate the sum of the dynamic range.

The code works, and is as follows:

Code:
Sub AutoSumTargetUrban()
 
    Const SourceRange = "N:N"
    Dim NumRange As Range, formulaCell As Range
    Dim SumAddr As String
    Dim c As Long
    For Each NumRange In Columns(SourceRange).SpecialCells(xlConstants, xlNumbers).Areas
        SumAddr = NumRange.Address(False, False)
        Set formulaCell = NumRange.Offset(NumRange.Count, 0).Resize(1, 1)
        formulaCell.Formula = "=SUM(" & SumAddr & ")"
        c = NumRange.Count
    Next NumRange
End Sub

I now need to use that sum in another computation but do not know how to reference the cell in the formula. The data begins in Row 17 of the worksheet and the sum is in the last row of Column N.

I am a newbie to VBA code and use a lot of code suggestions from this site (such as the code cited above). This seems relatively simply but my efforts to date have not worked. Any help would be appreciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hello

Code:
Sub AutoSumTargetUrban()
Dim NumRange As Range, fmlcell As Range, SumAddr$
For Each NumRange In Columns("n:n").SpecialCells(xlConstants, xlNumbers).Areas
    SumAddr = NumRange.Address(False, False)
    Set fmlcell = NumRange.Offset(NumRange.count).Resize(1, 1)
    fmlcell.Formula = "=SUM(" & SumAddr & ")"
    MsgBox "Formula was placed at " & fmlcell.Address & vbLf & "Value is " & fmlcell
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top