Worksheet functions – How to use the Excel function in VBA
Have you ever wondered how we can use the Excel function in VBA? Sheetfed functions come with help. As we know, the Excel spreadsheet offers us a number of useful functions. The resource of functions that we can use in the VBA code is a bit more limited. Thanks to VBA, we can easily use some of the functions offered by Excel data sheet. These are not all available functions, but they significantly extend and facilitate programming in VBA. In case we want to use the data sheet function, we can call it with a short commandin any VBA code in Excel: Application.WorksheetFunction . ENGLISH_INFORMATION_ID . The name of the function itself has to be introduced in accordance with English naming. Below is an example of the use of a rounding function, which we know from Excel under the name ZAOKR () . The example contains two versions. The first version is the use of the sheet function. The second example shows the analogous function that the VBA code offers us. The result itself is displayed in the form of the MsgBox window.
MsgBox "Wynik funkcji arkuszowej: " & Application.WorksheetFunction.Round(123.666, 2)
MsgBox "Wynik funkcji VBA: " & Round(123.666, 2)
As we can see in our example, the results of using our functions are the same.
VBA sheet functions – Tasks (You can enter the solution in a comment)
- Try out the function of max and min on any numerical data using the VBA sheet functions.
- Check if the VLOOKUP function () can be called via the VBA code. The solution can be found in this article.