excel vba‎ > ‎

Export without duplicate quotes

posted Jan 16, 2014, 1:27 AM by Roberto Felicini
Sub ExportRange()
    Dim ExpRng As Range
    Open ThisWorkbook.Path & "\textfile.txt" For Output As #1
    
    Set ExpRng = Worksheets("book2").Range("A1").CurrentRegion
    FirstCol = ExpRng.Columns(1).Column
    LastCol = FirstCol + ExpRng.Columns.Count - 1
    FirstRow = ExpRng.Rows(1).Row
    LastRow = FirstRow + ExpRng.Rows.Count - 1
    For r = FirstRow To LastRow
        For c = FirstCol To LastCol
             '  data = ExpRng.Cells(r, c).Value
            Data = Data & " " & ExpRng.Cells(r, c).Value
            If c = LastCol Then
                Print #1, Data
                Data = ""
            End If
        Next c
    Next r
    Close #1
End Sub
Comments