Lesson#125: How to use function with VBA

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.

See also  Lesson#180: How do you copy a color from one cell to another?

Hi! I am Puspendu. I am the founder and author of Excelabcd. I am little creative person, blogger and Excel-maniac guy. I hope you enjoy my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

*