REAL-TIME

VBA Projects

Full Access with Source Code

  • Designed and Developed by PNRao

  • Full Access with VBA Source Code

  • Well Commented Codes Lines

  • Creative and Professional Design

120+ PROFESSIONAL

Project Management Templates

120+ PM Templates Includes:
  • 50+ Excel Templates

  • 50+ PowerPoint Templates

  • 25+ Word Templates

Effortlessly Manage Your Projects

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

Share Post

Description:

There are many built-in functions available in Excel Worksheet functions and VBA functions. We can find some functions in both Excel Worksheet functions and VBA functions, for examples TRIM, MIN, MAX, etc. We can not find some Excel Worksheet functions like VLOOKUP,HLOOKUP, SUMIF in VBA.

What if you want to use VLOOKUP in VBA. Yes, we do not have VLOOKUP function in VBA, however we can use Excel Worksheet functions in VBA. We will see how to use Excel worksheet function VBA.

How to use Excel worksheet function VBA?:

We can use all worksheet functions using Application.WorksheetFunction object. All the worksheet functions are available in Application.WorksheetFunction object.

Examples to use Excel worksheet function in Excel VBA

Here are the examples to use Excel worksheet function in Excel VBA. We will see some of the Excel worksheet functions with examples.

Example on using SUM Excel Worksheet Function in VBA

The below example code to show you how to use SUM Excel Worksheet Function in VBA. Here we will sum the range A1 to A15.

Sub ExampleWorksheetFunction_SUM()

     MsgBox Application.WorksheetFunction.Sum(Range("A1:A15"))

End Sub
Instructions:
  1. Open an excel workbook
  2. Enter some values in A1 to A15 in the active worksheet
  3. Press Alt+F11 to open VBA Editor
  4. Insert a Module for Insert Menu
  5. Copy the above code and Paste in the code window
  6. Save the file as macro enabled workbook
  7. Press F5 to execute it
  8. It should prompt a message with total of the given values
Example on using VLOOKUP Excel Worksheet Function in VBA

The below example code to show you how to use SUM Excel Worksheet Function in VBA. Here we will sum the range A1 to A15.

Assume that we have data as shown below, we want use the vlookup function to find the Age of a given person name.

excel vlookup worksheet function in VBA

It is good idea to assign the arguments to variables then use in the functions.

Sub ExampleWorksheetFunction_VLookup()

lookupVal = "Kelly"
lookupRange = Range("A1:B5")

MsgBox Application.WorksheetFunction.VLookup(lookupVal, lookupRange, 2, False)

End Sub
Instructions:
  1. Open an excel workbook
  2. Enter the data in A1 to B5 in the active worksheet as shown in the above screen-shot
  3. Press Alt+F11 to open VBA Editor
  4. Insert a Module for Insert Menu of VBE
  5. Copy the above code and Paste in the code window
  6. Save the file as macro enabled workbook
  7. Press F5 to execute it
  8. It should prompt a message with 28 as a lookup value for given value (Kelly) in the table.
Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Project Management Templates

All-in-One Pack
120+ Project Management Templates

Essential Pack
50+ PM Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project
Management Template
Ultimate Resource
Management Template
Project Portfolio
Management Templates
Categories: Excel VBALast Updated: June 17, 2022

Leave A Comment