sumif on multiple sheet via vba

glebret

New Member
Joined
Sep 16, 2015
Messages
13
Hi,

I have a whole bunch of sheets and they all structured the same way. The all contain: the name of my client in column a, the real amount of expenses in column B, the budget amount in column C and a line for the total. I also have a summary sheets containing the name of all my clients and I would like to add the total of each column on that sheet. I have tried to get the total for just one column but there is a problem with one line of code:

Range("A3").Offset(lSht, 1).Formula = "=(SUMIF('" & Worksheets(lSht).Name & "'!C[1], ""*Total*""," '"Worksheets(lSht).Name& "'!C[3])"

All my variables or declared and working fine since I use them elsewhere.

Can anyone help me?

Thank you
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi

You are using the R1C1 notation in the formula, but you are using the .Formula property of the range object, which is for the A1 notation. Try with the property .FormulaR1C1
 
Upvote 0
Hi,

I've tried but it does not work.
B3 is were I want my data on my summary sheet but my problem is that all the other sheets can contain more than one "total" line (that's why I use a sumif) and they don't have the same quantity of expenses, meaning that my total line won't be the same on each sheet.

Thank you.
 
Upvote 0
Hi

I did a quick test with your formula

With a workbook with several of the default worksheets (Sheet1, Sheet2,...) and the last one named Totals,

with the worksheet Totals active,

I ran this test code and got in A4:A6:

A4: =SUMIF(Sheet1!C:C; "*Total*";Sheet1!E:E)
A5: =SUMIF(Sheet2!C:C; "*Total*";Sheet2!E:E)
A6: =SUMIF(Sheet3!C:C; "*Total*";Sheet3!E:E)




Code:
Sub Test()
Dim lSht As Long

For lSht = 1 To 3
      Range("A3").Offset(lSht, 1).FormulaR1C1 = "=SUMIF('" &  Worksheets(lSht).Name & "'!C[1], ""*Total*"",'" &  Worksheets(lSht).Name & "'!C[3])"
Next lSht
End Sub


Does this help?
 
Upvote 0
Hi PGC,

Thanks, That helped a lot, I gad an extra parenthesis at the beginning of the formula, a "&" symbol and an apostrophe missing and also extra quotations marks. works great now. Thx

Best Regards

Glebret
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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