Excel to text file - special conditions

mike93alfa

New Member
Joined
Sep 8, 2004
Messages
4
Hi, I need to write the values of variable to a text file for use in another program. In Excel I will typically have in A1= Length and B1 =100 and then A2=Width and B2=50 and so on..I need to save / write to a test file in this format:

"Length"=100
"Width"=50
"Depth"=75

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Are you saying that you want something like this?


Excel 2010
ABCD
1Length100"Length"=100 "Width"=50 "Depth"=75
2Width50
3Depth75
Sheet1
 
Upvote 0
Something like this?
Change the path in red...
Code:
Sub WriteToFile()
Dim fsB As Object, CrtTxtFile As Variant, cell As Range, LastRow As Long
Set fsB = CreateObject("Scripting.FileSystemObject")
Set CrtTxtFile = fsB.CreateTextFile("[COLOR=#ff0000][B]C:\ESD\file.txt[/B][/COLOR]", True)
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
With CrtTxtFile
    For Each cell In Range("A1:A" & LastRow)
        .WriteLine """" & cell.Value & """=" & cell.Offset(0, 1).Value
    Next cell
    .Close
End With
End Sub
 
Upvote 0
Hi, I need to write the values of variable to a text file for use in another program. In Excel I will typically have in A1= Length and B1 =100 and then A2=Width and B2=50 and so on..I need to save / write to a test file in this format:

"Length"=100
"Width"=50
"Depth"=75

Thanks

Thanks BQardi. The code works perfectly and does exactly want I want!
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

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