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
Bookmarks