Lesson#125: How to use function with VBA

Hello, we are back again with a very basic VBA learning topic. How to use a function with VBA.
Here I am having an array with some random numeric values in the range A1:A10.

I want to make SUM, AVERAGE, MAX, and MIN in different cells, and I will use VBA for that.
So I have written code like this.
Sub calcu()
Range(“B1”).Value = “SUM”
Range(“B2”).Value = “AVERAGE”
Range(“B3”).Value = “MAX”
Range(“B4”).Value = “MIN”
Range(“C1”).Formula = “=sum(A1:A10)”
Range(“C2”).Formula = “=average(A1:A10)”
Range(“C3”).Formula = “=max(A1:A10)”
Range(“C4”).Formula = “=min(A1:A10)”
End Sub
Now it shows a result like this.

This is how to use function or formula with the use of VBA.
Leave a Reply