Excel VBA : Worksheet Functions

Best Online Course : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects & Case Studies
- Job Placement Assistance
- Get 10% off till Sep 11, 2017
- Batch starts from October 8, 2017

This tutorial shows you how to enter worksheet functions in Excel VBA.
How to enter worksheet function in Excel VBA
The function must be preceded by the word "WorkheetFunction" and then place "." (period).

Download the workbook used in the examples shown below. 

The data are shown in the image below:



Example 1 : Sum numbers in a range

Suppose you have data in range A2:A8. You want to sum numbers entered in the range A2:A8.
Sub SumRange()
Dim result As Double
result = WorksheetFunction.Sum(Range("A2:A8"))
MsgBox result
End Sub

Example 2 : Sum numbers in two columns

Suppose you have data in column A and B. You want to sum the columns of numbers.
Sub SumColumn()
Dim cresult As Double
cresult = WorksheetFunction.Sum(Columns(1), Columns(2))
MsgBox cresult
End Sub

Example 3 : Count the number of used cells in two columns

Suppose you have data in column A and B. You want to count the number of used cells in the columns.
Sub countcolumn()
Dim cresult As Double
cresult = WorksheetFunction.CountA(Columns(1), Columns(2))
MsgBox cresult
End Sub

Example 4 : Conditional count of a range of numbers

Suppose you have data in range A2:A8. You want to count the number of cells that have value greater than 20.
Sub condcount()
Dim cresult As Double
cresult = WorksheetFunction.CountIf(Range("A2:A8"), ">20")
MsgBox cresult
End Sub

 Example 5 : VLOOKUP Function

The data used in this example is shown in the image below :


Sub look()
Dim cresult As Double
cresult = WorksheetFunction.VLookup("Deepanshu", Range("D2:E5"), 2, 0)
MsgBox cresult
End Sub
Download the workbook

Excel Tutorials : 100 Excel Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

1 Response to "Excel VBA : Worksheet Functions"

  1. USEFUL INFORMATION WITH REAL TIME SCENARIOS ..

    ReplyDelete

Next → ← Prev