Creating *.dat files Using Excel Column

bl6691

New Member
Joined
Dec 22, 2012
Messages
3
Dear all,
Thanks for your helps for always. I m new to here but i follow you threads everytime. I would like to ask a code to create .dat extended files by using excels columns. For example ; at the excel at A column ( A1:A350 ) there are names ( example ; Analysis1, Analysis2...) I would like to create .dat extended files from these names in a specific location ( F:/Analysis/Analysis1.dat ). my first question is this. The other qoestion is how i could fill these created .dat files automatically? Example ; I want to write something inside of the "Analysis1.dat" file from my main excel "Sheet2".
Thanks in advance,
Best Regards
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi and Welcome to MrExcel.

Here's one way of doing it.

Code:
Public Sub CrDtFlAnWrSmToIt()
'Loop through first sheet's column A
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row 'Finds last row in column A
    'Change the path in quotes to suit
    Open "F:\Analysis\" & Range("A" & i).Value & ".dat" For Output As #1 'Create dat file
    'Here we write from Sheet2 Range A1 to the dat file
    Print #1, Sheets("Sheet2").Range("A1").Value
    Close #1 'Close file after writing to it
Next i
End Sub
 
Upvote 0
Thank you very much for your quick help, its very helpfull to me. So can i want some adition to macro if possible.
At the second sheet ( sheet2 ), i want A1 text to write at Analysis1.dat ( The first .dat file that have been created at Sheet1 A1 ), A2 text ( sheet2 ) to write A2 .dat file created. I hope its clear..
Thanks in advance
Regards.
 
Upvote 0
Glad to know that it helps.

You will have to amend the macro as below.
Rich (BB code):
Public Sub CrDtFlAnWrSmToIt()
'Loop through first sheet's column A
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row 'Finds last row in column A
    'Change the path in quotes to suit
    Open "F:\Analysis\" & Range("A" & i).Value & ".dat" For Output As #1 'Create dat file
    'Here we write from Sheet2 Range A1 to the dat file
    Print #1, Sheets("Sheet2").Range("A" & i).Value
    Close #1 'Close file after writing to it
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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