Writing the contents of cells into a file

MyHero

New Member
Joined
Jan 22, 2009
Messages
26
Hey Folks,

I have a bunch of values in column A, and I need to write (export) the entire column into a file called "ColumnA.dat".

Can someone please help me create an Excel Macro Script that would accomplish that?

Thanks in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
what is the version of excel u r using. Also can u send the sample of data. also can you make sure your sheet name is Sheet1 in the workbook.
 
Upvote 0
try
Assuming ColumnA.dat resides in the same foloder as ThisWorkbook.
Code:
Sub test()
Dim txt As String
With Range("a1", Range("a" & Rows.Count).End(xlUp))
    txt = Join(Evaluate("transpose(" & .address & ")"), vbCrLf)
End With
Open ThisWorkbook.Path & "\ColumnA.dat", For Append As #1
    Print #1, txt
Close #1
End Sub
 
Upvote 0
Correction
delete comma on the line of
Rich (BB code):
Open ThisWorkbook.Path & "\ColumnA.dat", For Append As #1
 
Upvote 0
when I run your code I get the error "Compile Error: User-defined type not defined"

It then highlights:

Public Sub WriteRange(ByVal inputRange As Excel.Range, ByVal outputPath As String, _
Optional writeMode As eWriteMode =

Any ideas on how to improve your code?

Might be the enum, they aren't supported in all versions. What version of Excel are you using?
 
Upvote 0
Correction
delete comma on the line of
Rich (BB code):
Open ThisWorkbook.Path & "\ColumnA.dat", For Append As #1
Thank you all! Seiya's code worked like a charm! Thank you very much!

If I wanted to change the location, based on the contents of a cell, let's say B5, how could I modify the code?
 
Upvote 0
Thank you all! Seiya's code worked like a charm! Thank you very much!

If I wanted to change the location, based on the contents of a cell, let's say B5, how could I modify the code?
as well, if I wanted to change the name of the file based on a value in B6, if possible.
 
Upvote 0
How do you want the data to appear in the new file?

If you want to change the file name just use Range("B6") here instead of the hard-coded "\Column.DAT".
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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