Excel New Functions for Importing Text & CSV Files
In this article
Yes, Microsoft Excel has introduced new functions specifically designed to import and transform text and CSV files directly within a formula: VSTACK, HSTACK, TEXTSPLIT, and the updated POWER QUERY integration. These functions, available in Excel 365 and Excel 2021, allow you to pull data from external text files, split it into columns, and combine multiple files without the need for manual import wizards or VBA macros.
Background: How Excel Handled Text Files Before
Historically, importing a CSV or text file into Excel required using the Data tab and the From Text/CSV command, which launched the Text Import Wizard. This wizard walked you through choosing delimiters (commas, tabs, semicolons), setting data types, and placing the data in a worksheet. While functional, this process was static: if the source file changed, you had to re-run the wizard. For power users, the alternative was writing VBA code or using Power Query, which is a robust but separate tool that many casual users find intimidating.
The new functions change this paradigm by making text file handling a formula-based, dynamic operation. You can now reference a file path in a formula, and Excel will pull the data in, split it, and even combine multiple files, all while automatically updating when the source data changes.
How the New Functions Work
The core functions are:
- VSTACK: Vertically stacks arrays or ranges. When used with file references, it can combine the contents of multiple CSV files into one continuous column of rows.
- HSTACK: Horizontally stacks arrays, useful for merging data from different files side-by-side.
- TEXTSPLIT: Splits a text string into rows and columns based on a delimiter. This is ideal for parsing a single cell that contains comma-separated values.
- POWER QUERY: While not a function per se, Power Query has been integrated more deeply with the Data tab, and its From Text/CSV option now generates a dynamic query that can be refreshed with a single click.
For example, to import all CSV files from a folder, you can use a formula like:
=VSTACK(TEXTSPLIT(TEXTJOIN(",",TRUE,FILELIST("C:\Data\*.csv")),","," "))
This formula lists all files, joins their contents, splits by commas and spaces, and stacks them vertically. The exact syntax may vary depending on your Excel version and how you reference files.
How to Choose the Right Method
Deciding between the new functions and the traditional import wizard depends on your needs:
- Use VSTACK/HSTACK when you have multiple similarly structured CSV files that you want to combine into one table, and you want the result to update automatically.
- Use TEXTSPLIT when you have a single cell or a column of text that needs to be split into multiple columns, such as a list of names or addresses.
- Use Power Query when you need to perform complex transformations (filtering, pivoting, merging) before loading data, or when you need to connect to databases or web sources.
- Use the classic wizard for a one-off import where you don’t need automation.
For most users, Power Query remains the most powerful and flexible option, but the new functions are excellent for quick, formula-driven imports.
Common Problems and Solutions
- Problem: The new functions are not available. Solution: Ensure you have Excel 365 (current channel) or Excel 2021. These functions are not available in older versions like Excel 2016 or 2019.
- Problem: VSTACK returns a #VALUE! error. Solution: This often happens when the file paths are incorrect or the files are not accessible. Double-check the folder path and ensure the files are not open in another program.
- Problem: TEXTSPLIT doesn’t handle line breaks. Solution: Use the
CHAR(10)function to specify line breaks as a delimiter. For example:=TEXTSPLIT(A1,CHAR(10)). - Problem: Imported data is not updating. Solution: If you used Power Query, click Refresh All on the Data tab. If you used formulas, ensure your workbook is set to Automatic calculation mode.
Comparison: New Functions vs. Power Query vs. Classic Wizard
| Method | Best For | Dynamic? | Complexity |
|---|---|---|---|
| Classic Wizard | One-off simple imports | No | Low |
| VSTACK/HSTACK/TEXTSPLIT | Quick formula-based imports | Yes | Medium |
| Power Query | Complex transformations and automation | Yes | High |
If you only need to open a CSV file and view it, the classic wizard is fine. If you need to combine 50 CSV files into one clean table, Power Query is the most reliable. The new functions sit in between, offering a good balance for users who are comfortable with formulas.
Cost and Availability
These new functions are part of Microsoft 365 subscriptions and Excel 2021 (a one-time purchase). If you have an older perpetual license (Excel 2019 or earlier), you will not have access to VSTACK, HSTACK, or TEXTSPLIT. Upgrading to Microsoft 365 costs a monthly or annual fee, but it also provides continuous updates, which is how these functions were introduced. For business users, the cost is often justified by the time saved in data preparation.
Safety and Data Integrity
When importing text files, always be cautious about the source of the data. CSV files can contain formulas that Excel might execute if you open them directly. To avoid potential security risks:
- Use the Data tab’s From Text/CSV option instead of double-clicking a CSV file, as it gives you control over data types and prevents formula execution.
- When using VSTACK or TEXTSPLIT, ensure the file path is from a trusted location.
- Always back up your workbook before importing large datasets.
Additionally, be aware of delimiter inconsistencies: some CSV files use semicolons instead of commas, especially in European locales. Test your import with a small sample first.
Frequently Asked Questions
Can I use VSTACK to combine CSV files without opening them?
Yes, you can reference file paths in the formula, and Excel will read the contents directly. However, the files must be in a format that Excel can parse, and the path must be correct. The formula will not work if the files are password-protected or if the folder is not accessible.
Why does TEXTSPLIT not split my text into separate columns?
TEXTSPLIT requires you to specify both the row delimiter and the column delimiter. If you only provide a column delimiter, it will split into columns but keep everything in one row. For example, =TEXTSPLIT(A1,",") splits by commas into columns. To split into rows, use =TEXTSPLIT(A1,","," ") where the second delimiter is a space or line break.
Are these new functions available in Excel for Mac?
Yes, Microsoft 365 for Mac includes these functions as of 2022. The syntax is identical to Windows. If you are on an older Mac version, you may need to update.
Can I import a text file with a custom delimiter like a pipe (|)?
Yes. In TEXTSPLIT, you can use =TEXTSPLIT(A1,"|"). For Power Query, you can specify a custom delimiter in the import wizard. The classic wizard also allows custom delimiters.
What happens if the CSV file has headers?
If you use Power Query, you can promote the first row to headers. With VSTACK, you might need to manually remove the header row using the DROP function, which is also new in Excel 365. For example, =DROP(VSTACK(...),1) removes the first row.
Do these functions work with large files?
They can, but performance may degrade with very large files (hundreds of thousands of rows). For such cases, Power Query is more efficient because it uses a data compression engine and can handle millions of rows. Formula-based imports are best for moderate-sized data.