this doesn't actually work
It still exports the entire sheet even when a range is selected.
Please fix it
Kutools for Excel is a powerful add-in that frees you from performing time-consuming operations in Excel, such as combine sheets quickly, merge cells without losing data, paste to only visible cells, count cells by color and so on. 300+ powerful features / functions for Excel 2019, 2016, 2013, 2010, 2007 or Office 365!
It enables tabbed browsing, editing, and managing of Microsoft Office applications. You can open multiple documents / files in a single tabbed window, such as using the browser IE 8/9/10, Firefox, and Google Chrome. It's compatible with Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365. Demo
Kutools for Outlook is a powerful add-in that frees you from time-consuming operations which majority of Outlook users has to perform daily! It can save your time from using Microsoft Outlook 2019, 2016, 2013, 2010 or Office 365!
Kutools for Word is a powerful add-in that frees you from time-consuming operations which majority of Word users have to perform daily! It can save your time from using Microsoft Word / Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365!
Restores the old look and menus of Office 2003 to Microsoft Office 2019, 2016, 2013, 2010, 2007 or Office 365. Don’t lose time in finding commands on the new Ribbon. Easy to deploy to all computers in enterprises and organizations.
In Excel, we can save the whole worksheet as csv file by using the Save As function, but, have you ever tried to export a range of cells from one worksheet to a csv file? In this article, you will get the methods to solve this problem in Excel.
Here, I have a VBA code to export a range of cells from Excel to csv file, please do as follows:
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Export a range of cell contents to csv file
Sub ExportRangetoFile() 'Updateby Extendoffice Dim Rng As Range Dim WorkRng As Range Dim xFile As Variant Dim xFileString As String On Error Resume Next xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) Application.ActiveSheet.Copy Application.ActiveSheet.Cells.Clear WorkRng.Copy Application.ActiveSheet.Range("A1") Set xFile = CreateObject("Scripting.FileSystemObject") xFileString = Application.GetSaveAsFilename("", filefilter:="Comma Separated Text (*.CSV), *.CSV") Application.ActiveWorkbook.SaveAs Filename:=xFileString, FileFormat:=xlCSV, CreateBackup:=False End Sub
3. Then press F5 key to run this code, and a prompt box will pop out to remind you selecting the range of cells that you want to export as csv file.
4. And then click OK button, specify a directory for putting the new csv file, and give a name for the csv file in the File name text box, see screenshot:
5. Then click Save button, and the selected range has been saved as csv file, you can go to your specified folder to view it.
If you are not interested in the VBA code, here, I can introduce you an easy tool – Kutools for Excel, with its Export Range to File feature, you can quickly solve this job.
|Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.|
After installing Kutools for Excel, please do with following steps:
1. Select the data range that you want to export to csv file.
2. Then click Kutools Plus > Import & Export > Export Range to File, see screenshot:
3. In the Export Range to File dialog box, choose CSV(Comma delimited) from the File format option, and then specify the Save directory to save the new csv file, see screenshot:
4. Then click Ok button, a prompt box will pop out to remind you specify a name for this new csv file as you need, and then click OK to close this box, and the selected data will be exported as a CSV file at once.
Save the actual value: It will display the actual values in the final file.
Save values as shown on-screen: It will display the values in the final file as the same you read them on the computer screen.
Open the file after export: It will automatically open the final file after exporting the range if you check this option.