Introduction
Nowadays, excel is the essential requirement asked by almost all companies, whether they are dealing with data or have subsidiaries to deal with data. They expect each employee to know how to work with Excel in the brute force way, and the optimized way that saves time.
We can perform different operations in excel, and there are multiple ways to achieve them. Application object in excel provides or enable users to use other properties, functions, and procedures in excel that makes their work a lot easier and time-efficient.
We will learn all about application objects while proceeding with this blog, so let's get on with our topic without wasting more time.
Options in Application Object
Excel is often referred to as the mother of all objects, and we call it an application object. It provides us access to various operations in excel. We will learn about some of them in this part of the blog.
WorksheetFunction
Users can access the Excel functions by using WorksheetFunction. We will learn more about it by the following example.
- Insert a command button on your worksheet and add the following code to it.
Range("A5").Value = Application.WorksheetFunction.Average(Range("A1:A4"))
When the user clicks on the command button, then Excel VBA calculates the average of all the values from cell A1 to cell A4 and stores the result in the cell A% like, shown in the image below:
ScreenUpdating
Sometimes you become irritated with screen updating due to flickering, so in times like these ScreenUpdating function is great to use. We will learn how to use these functions by the example given below:
- Insert a command button on your worksheet and add the following code to it.
Dim i As Integer
For i = 1 To 10000
Range("A1").Value = i
Next i
Now, when the user clicks on the command button then, it will display all the values for a fraction of a second, as shown in the image below:
- You can speed up the process by updating the previous code with this code:
Dim I As Integer
Application.ScreenUpdating = False
For i = 1 To 10000
Range("A1").Value = i
Next i
Application.ScreenUpdating = True
This will increase the execution speed of your code, and as a result, you will directly see 10000.
DisplayAlerts
Sometimes displaying alerts becomes very necessary to save major errors in the future. You can achieve this by using the DisplayAerts function. You will learn how to use this function by the example given below:
- Insert a command button on your worksheet and add the following code to it.
ActiveWorkbook.Close
Now when the user clicks on the command button, Excel asks you to save the changes you made or not, as given below:
- This alert becomes irritating when you are executing the code, and to solve this, update the code with the following code:
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Calculation
The calculation is set to automatic by default. As a consequence, each time a value influencing a formula changes, Excel recalculates the file automatically. You may speed up your macro by setting calculation to manual if your worksheet has a lot of complex formulae.
- Insert a command button on your worksheet and add the following code to it.
Application.Calculation = xlCalculationManual
- You can verify this by yourself by clicking on File, Options, Formulas shown below:
- Now when you calculate the value of one cell, then the value of the other cell corresponding to it will not be changed, as shown in the image below:
- You may have to set the calculation to automatic at the end of your code, so to do so, add the following line at the end of your code:
Application.Calculation = xlCalculationAutomatic