Forum Discussion
Help with Formula/VBA
Krista1228 ,,
Yes you can use Excel function with VBA,, a few I would like to show that how to use.
Dim Minvalue as long
Minvalue = Application.WorksheetFunction.Min(Range("A1:A10").Value)
As soon you type Application and put DOT a list will appear need to pick the appropriate reserve word then DOT, the list of Excel Functions appears ,, pick one.
Another is,,
Range("A1").Formula = "=SUM(B1:B20)"
If you want to use Array (CSE) formula then use this :
Range("A1:A10").FormulaArray= "=Index($C$1:$C$10, Match(1,($D$1:$D$10=G1)*($E$1:$E$10=H1),0),1)"
- Krista1228Oct 08, 2020Copper Contributor
Thank you for replying!
I cant seem to get any of these to work when I put them in VBA and try to run as a Macro. Nothing happens. It does not show up in my macro list. When I put in the VBA Code
Dim Minvalue As Long
Minvalue = Application.WorksheetFunction.Min(Range("A1:A10").Value)
I get "Compile error: Invalid outside procedure"
- Rajesh_SinhaOct 09, 2020Iron Contributor
Krista1228 ,,
I was expecting that you can handle it ,, since are the SAMPLE code and need to use as SUBROUTINE,,,, using VB editor.
Anyways check the attached file,,, and read the instruction before U proceed.
- Please remember,,, the VBA code I've shown you are just SAMPLE code,, helps that how to use Excel formula with VBA code,,, you need to construct formula as needed.