0% found this document useful (0 votes)
45 views

Worksheet Function

There are fewer built-in functions in VBA than in Excel. However, Excel worksheet functions can be accessed in VBA using Application.WorksheetFunction.functionname(arguments). This statement allows VBA code to calculate functions like the base-10 logarithm of a number using Log10, even though there is no direct VBA function for it. As an alternative to using worksheet functions, some calculations can be done in VBA using combinations of natural logarithm functions.

Uploaded by

rehan69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Worksheet Function

There are fewer built-in functions in VBA than in Excel. However, Excel worksheet functions can be accessed in VBA using Application.WorksheetFunction.functionname(arguments). This statement allows VBA code to calculate functions like the base-10 logarithm of a number using Log10, even though there is no direct VBA function for it. As an alternative to using worksheet functions, some calculations can be done in VBA using combinations of natural logarithm functions.

Uploaded by

rehan69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Accessing Excel workbook functions within the VBA environment

There are much fewer built-in functions in VBA than in the Excel workbook environment. Fortunately, you can access
the Excel workbook functions using the Application.WorksheetFunction statement.

The general format for this statement is,


Application.WorksheetFunction.functionname(arguments)

where functionname is the name of the function in the Excel workbook environment.

For example, let’s say you want to calculate the base-10 logarithm of a number. There is no built-in function in VBA
specifically for this task. However, there is a built-in function in the workbook environment, named Log10, that
calculates the base-10 logarithm of a number. We can access the Log10 function within VBA in the following
manner:

Option Explicit
Sub main()
Dim x As Double, ans as double
x = 100
ans = Application.WorksheetFunction.Log10(x)
MsgBox ans
End Sub

If you don’t know what a logarithm is, don’t worry about it. You won’t be tested on this concept. Just choose your
favorite Excel worksheet function.

On a side note, if you want to calculate the base-10 logarithm within VBA without using the Log10 workbook
function, you would have to use a combination of natural logarithm functions, Log.

Option Explicit
Sub main()
Dim x As Double
x = 10
ans = Log(x)/Log(10)
MsgBox ans
End Sub

You might also like