How to Create User Defined Function through Excel VBA?
Tags: tocreateuserdefinedf, vbamacros
Published: 2021-09-14 12:41:19

---
title: How to Create User Defined Function through Excel VBA?
published: true
date: 2021-09-14 08:20:39 UTC
tags: ToCreateUserDefinedF,VBAMacros
canonical_url: https://geekexcel.com/how-to-create-user-defined-function-through-excel-vba/
---

In this tutorial, we will guide you on  **how to create user-defined**  **functions through Excel VBA**. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## User Defined Function

Microsoft Excel allows you to  **create your own function**  as per the requirement, we call it  **User Defined Function**.

## Example

- Firstly, you have to **create a range of strings** in Excel, from which we only want to **retrieve the text value** only.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-8.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you need to  **insert a module**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Insert-a-module.png)<figcaption>Insert a module</figcaption>

- You have to  **copy and paste**  the following code.

```
Function TextVba(entry)
For I = 1 To Len(entry)
ThisChar = Mid(entry, I, 1)
Select Case Asc(ThisChar)
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58
Case Else
TextVba = TextVba & ThisChar
End Select
Next i
End Function

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-35.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Then, you have to use this  **macro function**  as formula given below in the cell **B2**.

```
=TextVba(A2)
```

![](https://geekexcel.com/wp-content/uploads/2021/09/TextVBA-Function.png)<figcaption>TextVba Function</figcaption>

- Now, you need to **press enter ** on the keyboard.
- Finally, you have to press **Ctrl + D to copy to other cells** , then the function will **return** only **text** in the Microsoft Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-9.png)<figcaption>Output</figcaption>

## A Brief Synopsis

Here, we have explained the step-by-step procedure on **how to create user-defined functions through Excel VBA**. Make use of this. Please share your worthwhile  **feedback**  in the below  **comment**  section. To learn more, check out our website **[Geek Excel](https://geekexcel.com/)!!**

**Read Ahead:**

- **[Excel Formulas to Highlight the Cells Between Two Dates!!](https://geekexcel.com/excel-formulas-to-highlight-the-cells-between-two-dates/)**
- **[Extract the Missing Values through Excel VBA](https://geekexcel.com/how-to-extract-the-missing-values-through-excel-vba/)**
- **[Excel Formulas to Find the Missing Values From a list!!](https://geekexcel.com/excel-formulas-find-missing-values-from-a-list/)**
- **[Formulas to Find the Missing Value from a Range!!](https://geekexcel.com/excel-formulas-find-missing-value/)**
- **[Excel Formulas to Highlight the Missing Values ~ Easy Tutorial!!](https://geekexcel.com/excel-formulas-to-highlight-the-missing-values-easy-tutorial/)**