Alternative to using .Value

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I've read a few places that using .Value is frowned upon.

I'm ashamed to say that I use it frequently and would like to know what an alternative would be to something like the following.

VBA Code:
    Range("A12").Value = "Require vILT"
    Range("A13").Value = "Require ABE"
    Range("B3").Value = "=COUNTIFS(B16:B150,""SV-TECH*"",C16:C150,""N"")+COUNTIFS(B16:B150,""SV-BDC*"",C16:C150,""N"")+COUNTIFS(B16:B150,""SV-SD*"",C16:C150,""N"")+COUNTIFS(B16:B150,""SV-SF*"",C16:C150,""N"")"
    Range("B4").Value = "=COUNTIF(E16:E150,""Enrolled"")"
    Range("B5").Value = "=COUNTIFS(E16:E150,""Complete"",C16:C150,""N"")"

Or is what I'm doing okay in the realm of Excel?

Thank you
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Where you are setting values directly equal to a hard-coded value, you do not need it, i.e.
VBA Code:
Range("A12") = "Require vILT"

When you are trying to set a formula, you should NOT use it, but rather use .Formula (or .FormulaR1C1 if using R1C1 notation in your formula), i.e.
VBA Code:
Range("B4").Formula = "=COUNTIF(E16:E150,""Enrolled"")"
 
Upvote 0
Where you are setting values directly equal to a hard-coded value, you do not need it, i.e.
VBA Code:
Range("A12") = "Require vILT"

When you are trying to set a formula, you should NOT use it, but rather use .Formula (or .FormulaR1C1 if using R1C1 notation in your formula), i.e.
VBA Code:
Range("B4").Formula = "=COUNTIF(E16:E150,""Enrolled"")"
That saves me a few key strokes, thank you.
 
Upvote 0
Or

VBA Code:
Range("A3").Value = Evaluate("countif(E16:E150,""Enrolled"")")
 
Upvote 0
@JEC that will put the values, not the formula into the cell.
 
Upvote 0
Or

VBA Code:
Range("A3").Value = Evaluate("countif(E16:E150,""Enrolled"")")
Just to be clear, one puts the formula in the cell, the other puts the hard-coded value (the result of the calculation) in the cell.
So use whichever one serves your purpose.
 
Upvote 0
Yes, was just a suggestion. Which he can use or not ;)
 
Upvote 0
Just to be clear, one puts the formula in the cell, the other puts the hard-coded value (the result of the calculation) in the cell.
So use whichever one serves your purpose.
That makes sense, and in the long run it's the actual result that I'm really looking for to be in the cell, not the formula per say.
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

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