into
Technical User
- Dec 16, 2002
- 17
i want each row col a and b with data to export to textfile.
smaple txt file
A1
B1
A2
B2
for as long as there is data in A column
could someone help me get started.
this code is nice but not enough becouse it relyes on a selection.
smaple txt file
A1
B1
A2
B2
for as long as there is data in A column
could someone help me get started.
this code is nice but not enough becouse it relyes on a selection.
Code:
Option Explicit
Sub Export()
Dim fsoObject As Object
Dim fsoFile As Object
Dim rnCell As Range
Dim vaFilename As Variant
Dim lnRows As Long
Dim fsoObj As Object
Set fsoObject = CreateObject("Scripting.FilesystemObject")
vaFilname = Application.GetSaveAsFilename("c:\xl.txt", "Text File (*.txt),*.txt,ASCII File (*.asc),*.asc", 1, "export")
If vaFilnamn = False Then
MsgBox "No filename", vbInformation
Exit Sub
End If
'Set fsoObject = New Scripting.FileSystemObject
Set fsoFil = fsoObject.CreateTextFile(vaFilnamn, True)
lnRows = 0
For Each rnCell In Selection.Cells
If rnCell.Row <> lnRows Then
If lnRows <> 0 Then
fsoFil.write Chr(13) & Chr(10)
End If
lnRows = rnCell.Row
End If
If Left(rnCell.Address, 2) = "$A" Then
fsoFile.write "11"
fsoFile.write rnCell.Value
fsoFile.write Chr(13) & Chr(10)
ElseIf Left(rnCell.Address, 2) = "$B" Then
fsoFile.write "#12343;"
fsoFile.write rnCell.Value
fsoFile.write Chr(13) & Chr(10)
End If
Next rnCell
fsoFile.Close
Set fsoObject = Nothing
End Sub