how to use UDF to Extract the only Numbers in excel office vBA?
Tags: touseudftoextractthe, vbamacros
Published: 2021-09-22 11:40:50

---
title: how to use UDF to Extract the only Numbers in excel office vBA?
published: true
date: 2021-09-18 09:44:08 UTC
tags: ToUseUDFToExtractThe,VBAMacros
canonical_url: https://geekexcel.com/how-to-use-udf-to-extract-the-only-numbers-in-excel-office-vba/
---

In this tutorial, we will guide you on how to **use UDF to extract only numbers** in Excel Office 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)**

## Example

- Firstly, you need to  **create a sample data** with column A contains **alphanumeric data**  **& expected numbers** are in column B.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-22.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 option](https://geekexcel.com/wp-content/uploads/2020/09/1-106.png)<figcaption>Select the Visual Basic option</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Function NumericOnly(mystr As Variant)
Dim myOutput As String, i As Integer
    For i = 1 To Len(mystr)
        If IsNumeric(Mid(mystr, i, 1)) Then _
        myOutput = myOutput & Mid(mystr, i, 1)
    Next
NumericOnly = myOutput * 1
End Function

```

- 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-52.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>

- Now, to get the **output in cell B2** , you have to **use formula** given below.

```
=NumericOnly(A2)
```

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

- Finally, you will receive the  **output ** in the  **Microsoft Excel**.

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

## Conclusion

We hope that this short tutorial gives you guidelines on how to **use UDF to extract the only numbers** in Excel Office VBA. ** ** Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Continue Reading:**

- **[Excel Formulas to Find the Same Date in Next Year ~ Simple Guide!!](https://geekexcel.com/excel-formulas-to-find-the-same-date-in-next-year/)**
- **[Enter the Date in Excel Sheet ~ Step-by-Step Procedure!!](https://geekexcel.com/enter-the-date-excel/)**
- **[Find the Nth Largest Value in Excel Office 365 ~ Step-By-Step Procedure!!](https://geekexcel.com/find-the-nth-largest-value-in-excel/)**
- **[How to Extract Text Before Nth Specific Character in Excel?](https://geekexcel.com/extract-text-between-nth-specific-character-excel/)**
- **[Excel Formulas to Extract the Time from Date and Time ~ Quick Method!!](https://geekexcel.com/excel-formulas-to-extract-the-time-from-date-and-time/)**