Express formula in VBA

wasntme

New Member
Joined
Feb 1, 2019
Messages
37
Hi,

I am trying to change some formula in my file with VBA calculations, but as the formula is bit complex, have troubles expressing it in VBA. Result of the formula should be count of all projects started this month from 2 sheets different than the one it is present in. Formula in sheet works perfect.

Formula in sheet is:
Code:
COUNTIFS('VAT registrations'!M:M,">="&EOMONTH(TODAY(),-1)+1,'VAT registrations'!M:M,"<"&EOMONTH(TODAY(),0)+1,'VAT registrations'!E:E,"Registration")+COUNTIFS(Archive!L:L,">="&EOMONTH(TODAY(),-1)+1,Archive!L:L,"<"&EOMONTH(TODAY(),0)+1,Archive!E:E,"Registration")

Have tried to simply put it in VBA as:
Code:
Worksheets("Summary").Range("C18").Formula = "=COUNTIFS('VAT registrations'!M:M,">="&EOMONTH(TODAY(),-1)+1,'VAT registrations'!M:M,"<"&EOMONTH(TODAY(),0)+1,'VAT registrations'!E:E,"Registration")+COUNTIFS(Archive!L:L,">="&EOMONTH(TODAY(),-1)+1,Archive!L:L,"<"&EOMONTH(TODAY(),0)+1,Archive!E:E,"Registration")"

But i get Compile error:expected end of statement.

Any help is greatly appreciated.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You could always record the placing of the formula in the cell, however that will result in a RC reference. You need to use two double quotes around your values where you want excel to place double quotes in the formula:

Range("C18").Formula = "=COUNTIFS('VAT registrations'!M:M,"">=""&EOMONTH(TODAY(),-1)+1,'VAT registrations'!M:M,""<""&EOMONTH(TODAY(),0)+1,'VAT registrations'!E:E,""Registration"")+COUNTIFS(Archive!L:L,"">=""&EOMONTH(TODAY(),-1)+1,Archive!L:L,""<""&EOMONTH(TODAY(),0)+1,Archive!E:E,""Registration"")"
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,658
Latest member
GStorm

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