CSV Export

gimli

New Member
Joined
Nov 11, 2009
Messages
37
Hello all,

Looking to export a range of cells to a csv file. I would like to name the file based on the data in a cell.
for ex:

A1 ="THIS IS A TEST"

So i would like to export all the data in cells b1:n100 to a csv called "THIS IS A TEST"
Not vba literate as id like to be.
Any help would be great!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this. This will take info from "Sheet1" (you can change that as noted) and save it as a CSV to your default Excel save location (you can change that too).

VBA Code:
Sub SaveAsCSV()
    
    Dim wb As Workbook
    Dim nam As String
    
    Application.DisplayAlerts = False
    With Worksheets("Sheet1")   'Change "Sheet1" to your sheet name.
        nam = Cells(1, 1)
        .Range("B1:N100").Copy
    End With
    Set wb = Workbooks.Add
    With wb
        ActiveSheet.PasteSpecial
        .SaveAs Filename:=nam & ".csv", FileFormat:=6, CreateBackup:=False   'you can change save location here
        .Close
    End With
    Application.DisplayAlerts = True
    
End Sub
 
Upvote 0
Hello, thanks for the help..got subscript out of range error for line
nam = .Cells(1, 1)

Not sure what that means... :(


VBA Code:
Sub SaveAsCSV()
    
    Dim wb As Workbook
    Dim nam As String
    
    Application.DisplayAlerts = False
    With Worksheets("Sheet1")   'Change "Sheet1" to your sheet name.
         nam = .Cells(1, 1)
        .Range("B1:N100").Copy
    End With
    Set wb = Workbooks.Add
    With wb
        ActiveSheet.PasteSpecial
        .SaveAs Filename:=nam & ".csv", FileFormat:=6, CreateBackup:=False   'you can change save location here
        .Close
    End With
    Application.DisplayAlerts = True
    
End Sub
 
Upvote 0
Try changing that line to:

VBA Code:
nam = Range("A1")
 
Upvote 0
Sorry about that, I left off the period.

Code:
nam = .Range("A1")
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top