+ Reply to Thread
Results 1 to 3 of 3

Saving as pipe delimited

  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    5

    Saving as pipe delimited

    I am new to VBA and I have encountered a challenge that I am hoping someone can help me solve. The spreadsheet has the first 4 rows with miscellaneous headers, then there are numerous rows with dropdown boxes in various cells (rows 5 - 899), not all rows will be populated because it depends on how many entries the user needs to make. In the macro I am deleting the first 4 rows and writing it out to a pipe delimited file. Let's assume for this issue there is only two rows of data after deleting the first 4 rows and 40 columns. My code is below. The issue is row 3 - 899 all show in the file as |||||||||||||||||||||||||||||||||||||||| and I would like to eliminate these extra lines.

    Sub SaveAsPipeDelimited()


    Dim vFileName As Variant
    Dim rngLastCell As Range
    Dim lLastRow As Long
    Dim nLastCol As Integer
    Dim lCurrRow As Long
    Dim nCurrCol As Integer
    Dim sRowString As String


    Rows("1:4").Select
    Selection.Delete Shift:=xlUp
    vFileName = Application.GetSaveAsFilename(filefilter:= _
    "Text Files (*.txt), .txt")
    If vFileName <> False Then
    Open vFileName For Output As #1
    Set rngLastCell = ActiveSheet.Range("A1"). _
    SpecialCells(xlLastCell)
    lLastRow = rngLastCell.Row
    nLastCol = rngLastCell.Column
    For lCurrRow = 1 To lLastRow
    sRowString = ActiveSheet.Cells(lCurrRow, 1).Formula & "|"
    For nCurrCol = 2 To nLastCol
    sRowString = sRowString & ActiveSheet _
    .Cells(lCurrRow, nCurrCol).Formula & "|"
    Next nCurrCol
    If Len(sRowString) = nLastCol - 1 Then
    '/ print blank line only
    Print #1, sRowString & ""
    Else
    Print #1, sRowString & ""
    End If
    Next lCurrRow
    Close #1
    End If
    End Sub

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Saving as pipe delimited

    Here is a version of your code that avoids outputting lines with pipe only:

    Please Login or Register  to view this content.
    Gary's Student

  3. #3
    Registered User
    Join Date
    01-21-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Saving as pipe delimited

    Thank you. This worked like a charm.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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