KutoolsforOffice — One Suite. Five Tools. Get More Done.

How to Extract File Extensions from Filenames in Excel

AuthorKellyLast modified

When working with file lists in Excel, you may need to identify file types by extracting their extensions, such as .xlsx, .docx, .pdf, or .jpg. This can be useful for organizing files, filtering specific file types, creating reports, or preparing data for further analysis. While extracting extensions manually from a few filenames is manageable, doing so for hundreds or thousands of filenames can be tedious and time-consuming.

In this tutorial, we'll show you three practical methods to extract file extensions from filenames in Excel: using a formula, a VBA function, and the powerful Extract Text feature of Kutools for Excel.


Extract file extensions from filenames with a formula

If you prefer a built-in Excel solution, you can use a formula to extract file extensions directly from filenames. The formula you use depends on your Excel version.

For Excel 365, Excel 2021, and later versions

Modern Excel versions include the TEXTAFTER function, which makes extracting file extensions much easier.

Steps

  1. Select a blank cell next to your filename list and enter the following formula:
    ="."&TEXTAFTER(A2,".",-1)
    Note: Replace A2 with the cell containing your filename.
  2. Press Enter to get the result for the first filename.
  3. Then drag the Fill Handle down to copy the formula to the remaining cells.
    a screenshot shows how to apply formula to extract file extension in Excel 365, 2021 and above

For Excel 2019, Excel 2016, and earlier versions

If your version of Excel does not support TEXTAFTER, you can use the following formula instead.

Steps

  1. Select a blank cell next to your filename list and enter the following formula:
    =RIGHT(A2,LEN(A2)-FIND("@",SUBSTITUTE(A2,".","@",LEN(A2)-LEN(SUBSTITUTE(A2,".",""))))+1)
    Note: Replace A2 with the cell containing your filename.
  2. Press Enter to get the result for the first filename.
  3. Then drag the Fill Handle down to copy the formula to the remaining cells.
    a screenshot shows how to apply formula to extract file extension in Excel 2019 and earlier

Advantages of the formula methods

  • No VBA required
  • No additional tools required
  • Suitable for quick extraction tasks
  • Works well for most filename lists

However, formulas can become difficult to remember and maintain, especially when working with large datasets.


Extract file extensions from filenames with VBA

If you prefer using a custom function instead of a worksheet formula, you can extract file extensions with VBA. By creating a simple user-defined function, you can return the extension from a filename directly in a worksheet cell.

Steps

  1. Press Alt + F11 to open the Microsoft Visual Basic for Applications window.
  2. Click Insert > Module.
  3. Copy and paste the following code into the module window:
    Function GetExtension(FileName As String) As String
        Dim Pos As Long
        Pos = InStrRev(FileName, ".")
        If Pos > 0 Then
            GetExtension = Mid(FileName, Pos)
        Else
            GetExtension = ""
        End If
    End Function
    a screenshot shows how to use the VBA code in the VBA editor
  4. Close the VBA Editor and return to your worksheet.
  5. In a blank cell, enter the following formula and press Enter.
    =GetExtension(A2)
  6. Drag the Fill Handle down to apply the function to the remaining rows.
    The custom function extracts the file extension including the period as shown in the screenshot below.
    a screenshot shows the extracted extensions by applying the user-defined function
Note: Since this method uses VBA, the workbook must be saved as a macro-enabled workbook (.xlsm) to preserve the custom function. If the workbook is saved in the standard Excel format (.xlsx), the VBA code will be removed. Additionally, macros must be enabled when opening the workbook; otherwise, the custom function will not work.

Extract file extensions from filenames with Kutools for Excel

For the fastest and most user-friendly solution, Kutools for Excel provides the Extract Text feature, allowing you to extract file extensions without writing formulas or VBA code. With its rule-based extraction capability, you can process large filename lists in just a few clicks.

Kutools for Excel - Packed with over 300 essential tools for Excel. Make Excel tasks faster, easier, and more efficient. Download now!

Steps

  1. Click Kutools > Text > Extract Text.
    a screenshot shows how to enable the extract text feature
  2. In the Extract Text dialog box:
    1. Switch to the Extract by rule tab.
    2. Select the cells containing the filenames from which you want to extract extensions.
    3. Enter the following rule in the Text box:
      .*
  3. Click Add to add the rule.
  4. Click OK.
    a screenshot shows how to create a extract rule
  5. In the dialog box that appears, specify the output range and click OK.
    a screenshot of selecting the output cell
Notes:
  • This rule uses wildcard matching. The period (.) matches the dot that separates the filename from its extension, while the asterisk (*) matches any number of characters that follow the dot. As a result, the rule extracts the file extension, including the period, from each filename.
  • The Extract by rule feature also supports other wildcard characters:
    * — Matches any number of characters.
    ? — Matches any single character.
    For example, if you use this rule .???, Kutools extracts only file extensions consisting of exactly three characters after the period, such as .jpg, .png, and .txt.

Kutools for Excel - Supercharge Excel with over 300 essential tools, making your work faster and easier, and take advantage of AI features for smarter data processing and productivity. Get It Now

Result

Kutools immediately extracts all file extensions, including the period (.), from the selected filenames and outputs them into the specified range.

a screenshot the extracted results

Even large filename lists can be processed instantly without any formulas or manual editing.


Conclusion

Extracting file extensions can help you organize, analyze, and manage file-related data more efficiently. While formulas provide a quick worksheet-based solution and VBA offers a reusable custom function, both methods require either formula knowledge or coding skills.

If you're looking for the simplest and most efficient approach, Kutools for Excel's Extract Text feature is the best choice. Its rule-based extraction process eliminates the need for formulas and VBA, allowing you to extract file extensions from large filename lists quickly and accurately with just a few clicks.


Best Office Productivity Tools

🤖Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |  Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |  Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

All Kutools add-ins. One installer

Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.

ExcelWordOutlookTabsPowerPoint
  • All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
  • One installer, one license — set up in minutes (MSI-ready)
  • Works better together — streamlined productivity across Office apps
  • 30-day full-featured trial — no registration, no credit card
  • Best value — save vs buying individual add-in