how to Remove Extra Commas In Notepad from Microsoft Excel?
Tags: toremoveextracommasi, vbamacros
Published: 2021-09-16 02:28:20

---
title: how to Remove Extra Commas In Notepad from Microsoft Excel?
published: true
date: 2021-09-15 10:34:44 UTC
tags: ToRemoveExtraCommasI,VBAMacros
canonical_url: https://geekexcel.com/how-to-remove-extra-commas-in-notepad-from-microsoft-excel/
---

In this article, we will talk about how to **remove extra commas in Notepad from Microsoft Excel**  by using the following steps in VBA. Let’s see 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

- 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-8-1024x180.png)<figcaption>Select Visual Basic</figcaption>

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

```
Sub test()
    Dim fn As String, txt As String
    fn = Application.GetOpenFilename("TextFiles,*.txt")
    If fn = "" Then Exit Sub
    txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
    With CreateObject("VBScript.RegExp")
        .Global = True: .MultiLine = True
        .Pattern = ",+$"
        Open Replace(fn, ".txt", "_Clean.txt") For Output As #1
            Print #1, .Replace(txt, "")
        Close #1
    End With
End Sub

```

- 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-40-1024x422.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 make sure that your  **macro name is selected**  and click the  **Run ** button.

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

- Now, the above **code** will first ask you to **select the file** where it is located.

![](https://geekexcel.com/wp-content/uploads/2021/09/Select-the-File-1.png)<figcaption>Select the File</figcaption>

- After the **code runs** , you will get an **output file** with name **Test\_Clean**.

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

- To check whether the **code** is working fine or not; let us **open the .txt file** & view the results.

![](https://geekexcel.com/wp-content/uploads/2021/09/Open-.txt-file.png)<figcaption>Open the .txt file</figcaption>

- Finally, you can see the **last line** i.e. **line # 5** , which previously had unwanted commas at the end, has been fixed now.

## Wrap-Up

We hope that this tutorial gives you guidelines on **how to remove extra commas in Notepad from Microsoft Excel. ** 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/) **!!**

**Read Next:**

- **[Excel Formulas to Calculate Net Present Value (NPV) ~ Simple Guide!!](https://geekexcel.com/excel-formulas-to-calculate-net-present-value-npv/)**
- **[Calculate the Present Value of Annuity ~ Useful Tricks!!](https://geekexcel.com/excel-formulas-to-calculate-the-present-value-of-annuity/)**
- **[Excel Formulas to Get the Percentage Discount ~ Useful Tricks!!](https://geekexcel.com/excel-formulas-to-get-the-percentage-discount/)**
- **[use the MIRR function in Excel office 365? ~ {Quick Steps}](https://geekexcel.com/how-to-use-the-mirr-function-in-excel-office-365-quick-steps/)**
- **[Excel Formulas to Find Original Price from Percentage Discount!!](https://geekexcel.com/excel-formulas-to-find-original-price-from-percentage-discount/)**