loop and sum

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
782
Office Version
  1. 365
  2. 2010
Hello... i have a file in column A contains

"CURRENCY TOTAL: C$" mulitple times (eg A23)


-then I'm gonna make a sum formula from that point, but going 6 columns to the RIGHT and one row DOWN (in this case, the formula would be G24)

-in G24, it's gonna sum 2 numbers to the LEFT of it (in this case, F24 and F23)


...


could someone help me create a loop to look at all the "CURRENCY TOTAL: C$" in column A and then dynamically make the sum formula accordingly?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I think this does what you want, but its untested .
Code:
Sub daveyc18()
Dim Fnd As Range, fAdr As String
With Range("A:A")
    Set Fnd = .Find("CURRENCY TOTAL: C$", , xlFormulas, xlPart, , , True)
    If Not Fnd Is Nothing Then
        fAdr = Fnd.Address
    Else
        MsgBox "search string not found in col A"
        Exit Sub
    End If
    Do
        Fnd.Offset(1, 6).Formula = "=SUM(" & Fnd.Offset(0, 5).Resize(2, 1).Address & ")"
        Set Fnd = .FindNext(Fnd)
        If Fnd Is Nothing Then Exit Do
        If Fnd.Address = fAdr Then Exit Do
    Loop
End With
End Sub
 
Upvote 0
I think this does what you want, but its untested .
Code:
Sub daveyc18()
Dim Fnd As Range, fAdr As String
With Range("A:A")
    Set Fnd = .Find("CURRENCY TOTAL: C$", , xlFormulas, xlPart, , , True)
    If Not Fnd Is Nothing Then
        fAdr = Fnd.Address
    Else
        MsgBox "search string not found in col A"
        Exit Sub
    End If
    Do
        Fnd.Offset(1, 6).Formula = "=SUM(" & Fnd.Offset(0, 5).Resize(2, 1).Address & ")"
        Set Fnd = .FindNext(Fnd)
        If Fnd Is Nothing Then Exit Do
        If Fnd.Address = fAdr Then Exit Do
    Loop
End With
End Sub

worksgreat, thanks...had to change to xlvalues isntead of formulas for whatever reason
 
Last edited:
Upvote 0
worksgreat, thanks...had to change to xlvalues isntead of formulas for whatever reason
You are welcome - thanks for the reply. Most likely reason you had to change xlFormulas to xlValues is that your search term "CURRENCY TOTAL: C$" is in cells containing formulas. If that's the case, be sure to tell us in your initial post that some or all the cells holding the search term are formulaic cells!
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,251
Members
453,027
Latest member
Lost_in_spreadsheets

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