+ Reply to Thread
Results 1 to 2 of 2

Export to Txt Tab Delimited

  1. #1
    Registered User
    Join Date
    04-11-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Export to Txt Tab Delimited

    Hi I was hoping someone can help me

    I'm using the below code to export an entire sheet to TXT tab delimited file.


    When Its running the export I would like it to skip any rows where the value in Colomn H =0.00

    Many Thanks
    Adam


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ExportToTextFile
    ' This exports a sheet or range to a text file, using a
    ' user-defined separator character.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Sub ExportToTextFile(FName As String, _
    Sep As String, SelectionOnly As Boolean, _
    AppendData As Boolean)

    Dim WholeLine As String
    Dim FNum As Integer
    Dim RowNdx As Long
    Dim ColNdx As Integer
    Dim StartRow As Long
    Dim EndRow As Long
    Dim StartCol As Integer
    Dim EndCol As Integer
    Dim CellValue As String


    Application.ScreenUpdating = False
    On Error GoTo EndMacro:
    FNum = FreeFile

    If SelectionOnly = True Then
    With Selection
    StartRow = .Cells(1).Row
    StartCol = .Cells(1).Column
    EndRow = .Cells(.Cells.Count).Row
    EndCol = .Cells(.Cells.Count).Column
    End With
    Else
    With Sheet5.UsedRange
    StartRow = .Cells(1).Row
    StartCol = .Cells(1).Column
    EndRow = .Cells(.Cells.Count).Row
    EndCol = .Cells(.Cells.Count).Column
    End With
    End If

    If AppendData = True Then
    Open FName For Append Access Write As #FNum
    Else
    Open FName For Output Access Write As #FNum
    End If

    For RowNdx = StartRow To EndRow
    WholeLine = ""
    For ColNdx = StartCol To EndCol
    If Cells(RowNdx, ColNdx).Value = "" Then
    CellValue = Chr(34) & Chr(34)
    Else
    CellValue = Cells(RowNdx, ColNdx).Value
    End If
    WholeLine = WholeLine & CellValue & Sep
    Next ColNdx
    WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
    Print #FNum, WholeLine
    Next RowNdx

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

    End Sub
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' END ExportTextFile
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    Sub DoTheExport()

    ExportToTextFile FName:="D:\Temp\Export.TXT", Sep:=vbTab, _
    SelectionOnly:=False, AppendData:=False
    MsgBox "Export Complete"
    End Sub

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Export to Txt Tab Delimited

    You're providing your own answer
    Add an IF THEN ELSE statement
    before the actual export
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Complex Loop Pipe-Delimited Data Export
    By cnash52 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-28-2016, 04:24 PM
  2. Export to Tab-Delimited Text File Not working!
    By AGALLEGOS in forum Excel General
    Replies: 1
    Last Post: 09-17-2014, 11:20 AM
  3. Export as Tab Delimited
    By jpaperguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2013, 01:45 PM
  4. [SOLVED] Export rows to delimited txt files
    By jmspen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2012, 05:20 PM
  5. Export Multiple Tabs to Pipe Delimited Txt
    By Machie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2010, 08:32 PM
  6. [SOLVED] Export to Tab Delimited Text Error
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2006, 11:25 AM
  7. [SOLVED] How do I export XLS to TXT delimited by '|'?
    By Mohsin Ghani in forum Excel General
    Replies: 2
    Last Post: 02-11-2005, 12:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1