View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel[_825_] joel[_825_] is offline
external usenet poster
 
Posts: 1
Default Problem with exported text


I made the code handle all posible situations which made in a little
bit more complicated.


Sub Button1_Click()
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''
' This exports the data to a semicolon seperated text file.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''
Dim fileName As String
'Dim inputRow As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim EndRow As Long
Dim CellValue As String
Dim currPath As String
Dim slnum As String

slnum = UCase(Range("C8:C8").Value)
Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile
currPath = ActiveWorkbook.Path
fileName = currPath & "\" & slnum & "_Appendix1data.TXT"
Open fileName For Output Access Write As #FNum

With ActiveSheet

'get last row of data
EndRow = 0
For ColNdx = 1 To 24
LastRow = .Cells(Rows.Count, Colcount).End(xlUp).Row
If LastRow EndRow Then
EndRow = LastRow
End If
Next ColNdx


If EndRow = 8 Then
For RowNdx = 8 To EndRow
LastCol = .Cells(RowNdx, Columns.Count).End(xlToLeft).Column
If LastCol < 1 Or .Cells("A" & RowNdx) < "" Then

For ColNdx = 1 To LastCol
CellValue = Cells(RowNdx, ColNdx).Text

If ColNdx = 1 Then
OutputLine = CellValue
Else
OutputLine = OutputLine & ";" & CellValue
End If
Next ColNdx
Print #FNum, OutputLine
End If
Next RowNdx
End If
End With


EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

MsgBox ("Formated Data is stored in " & fileName)

End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=189337

http://www.thecodecage.com/forumz/chat.php