Excel formula question

J15491

New Member
Joined
Jan 10, 2020
Messages
34
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have the following formula in a database worksheet cell, =SUMIFS($N$2:$N$1048571,$T$2:$T$1048571,$AD2,$S$2:$S$1048571,"Utilities"). It works in my worksheet(Sheet2) and populates the data to my Dashboard. My problem is this: When I start a new month erasing all the data in my user form database, the values in sheet 2 are cleared. As a result Cells J17, M17 and N17 show !#Ref because cells AC2, AE2 and AF2 are now empty. I'm not sure how to fix this. I'm also wondering how to code the above formula in excel vba.

I tried this, but it didn't work



Sub Formula_BudgetTotals()

'Assigns hard code formula to a single cell.

Range("AC2").Formula = "=SUMIFS($N$2:$N$1048571,$T$2:$T$1048571,$AD2,$S$2:$S$1048571,"Utilities")"

End Sub



Hope I explained it well enough.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
"erasing all the data "
Are you delting the rows or clearing just the cells ??
How are you clearing the data ?? manually or via VBA ?
And why are your formula extending to over 1 million rows ?
 
Upvote 0
I agree with Michael that setting a formula to such a large data range is not doing the spreadsheets performance any favours.
But in terms of getting your code working just put double quotes around your string variable eg ""Utilities""
VBA Code:
Sub Formula_BudgetTotals()

    'Assigns hard code formula to a single cell.
   
    Range("AC2").Formula = "=SUMIFS($N$2:$N$1048571,$T$2:$T$1048571,$AD2,$S$2:$S$1048571,""Utilities"")"

End Sub
 
Upvote 0
"erasing all the data "
Are you delting the rows or clearing just the cells ??
How are you clearing the data ?? manually or via VBA ?
And why are your formula extending to over 1 million rows ?
Actually I currently delete the data entered in the userform database with a command button by highlighting each row of data and clicking delete. I plan to add a command button that will erase all rows of data from the database with one click. I just need to work out the code for that. The current delete button is used to delete one row of data. As far as the formula goes I planned to extend it to just 50 rows. The data is entered into the text boxes on the userform and then populated to the appropriate cells in sheet2.
 
Upvote 0
Maybe post the code you are using at the moment AND what else you want done with it !!
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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