1. VBA Code for SUMIF

I have a spreadsheet where I want all the values in Column D that corresponds to text "CURRENT CLOSING BALANCE" to total using SUMIF. If I use the SUMIF formula manually I get the correct vanswer, but gett zero when using the sumif formula in a macro. See attached workbook

My code is as follows:

HTML Code:
```Finalrow = Range("D65536").End(xlUp).Row
Range("C" & Finalrow + 3).Value = "CURRENT CLOSING BALANCE"
Range("D" & Finalrow + 3).Formula = "=sumif(C1:D" & Finalrow  & ", ""CURRENT CLOSING BALANCE"", D1:D" & Finalrow & ")"```
Your assistance in resolving this will be most appreciated

2. Why a macro when a spreadsheet formula would suffice?

=SUMIF(C:C ,"*CURRENT CLOSING BALANCE*", D : D )

I put the * around CURRENT CLOSING BALANCE because you have spaces in those words.

You can remove the spaces from the D's. The website was turning it into a smilie.

or for the macro, try

Code:
```Sub sumcurrent()
Dim Finalrow As Long
Finalrow = Range("D65536").End(xlUp).Row
Range("C" & Finalrow + 3).Value = "CURRENT CLOSING BALANCE"
Range("D" & Finalrow + 3).Formula = "=sumif(C1:D" & Finalrow & ", ""*CURRENT CLOSING BALANCE*"", D1:D" & Finalrow & ")"
End Sub```

3. The Following User Says Thank You to jrb For This Useful Post:

HowardC (2012-05-09)

4. Thanks for the help, code works perfectly

5. JRB,

To prevent problems with formulas converting to smilies place them in [noparse] [*noparse] tags.
Ex: =SUMIF(C:C ,"*CURRENT CLOSING BALANCE*", D:D )
Of course I had to replace the / {backslash} for the ending tag with a * so I could nest the tags.

6. The Following User Says Thank You to RetiredGeek For This Useful Post:

jrb (2012-05-09)

Posting Permissions

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