Rudimentary VBA Question -- Formula calculate in VBA display result

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - I have a very basic VBA question. I have two cells; where I want VBA to calculate the result in VBA and then just put the value in the cell for example:

Current
Cell B5: =COUNTIFS('D'!B1:B1000,$A$3)
Cell B6: =COUNTIFS(C1:C1000,">"&0,C1:C1000,"<>98",F1:F1000,"M")

Desired

VBA handles the calculation

Cell B5: result only
Cell B6: result only
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
How about
VBA Code:
Range("B5").Value = [COUNTIFS('D'!B1:B1000,$A$3)]
Range("B6").Value = [COUNTIFS(C1:C1000,">"&0,C1:C1000,"<>98",F1:F1000,"M")]
 
Upvote 0
How about
VBA Code:
[QUOTE="Fluff, post: 5608954, member: 289073"]
Range("B5").Value = [COUNTIFS('D'!B1:B1000,$A$3)]
Range("B6").Value = [COUNTIFS(C1:C1000,">"&0,C1:C1000,"<>98",F1:F1000,"M")]
[/QUOTE]
I am getting this error is it related to me added this?

#VALUE!

VBA Code:
With Sheets("Compare")
.Range("B5").Value = [COUNTIFS('D'!B1:B1000,$A$3))]
.Range("B6").Value = [COUNTIFS(C1:C1000,">"&0,C1:C1000,"<>98",F1:F1000,"M"))]
End With
 
Upvote 0
Desired
VBA handles the calculation

Range("B5") = WorksheetFunction.CountIfs(Sheets("D").Range("B1:B1000"), Range("A3"))
Range("B6") = WorksheetFunction.CountIfs(Range("C1:C1000", ">0", Range("C1:C1000", "<>98", Range("F1:F1000", "M"))
 
Upvote 0
You also need to add a period before the square brackets like
VBA Code:
With Sheets("Compare")
   .Range("B5").Value = .[COUNTIFS('D'!B1:B1000,$A$3)]
   .Range("B6").Value = .[COUNTIFS(C1:C1000,">"&0,C1:C1000,"<>98",F1:F1000,"M")]
End With
 
Upvote 0
Solution
Is that with the amendment in post#6?
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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