i need some help to understand line 23

adna21

New Member
Joined
Sep 10, 2022
Messages
6
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
what is the point of adding another tab if the previous line does it after each cell?
VBA Code:
Dim fso As Scripting.FileSystemObject
    Dim ts As Scripting.TextStream
    Dim r As Range
    Dim ColumnCount As Integer
    Dim i As Integer
    
    Set fso = New Scripting.FileSystemObject
    
    ' Open for writing
    Set ts = fso.OpenTextFile( _
        Environ("UserProfile") & "\Desktop\TestExcelFile.txt", ForWriting, True)
    
    ' activate Sheet1
    Sheet1.Activate
    
    ' determine number of columns to copy
    ColumnCount = Range("A1", Range("A1").End(xlToRight)).Cells.Count
    
    ' iterate through rows and columns
    For Each r In Range("A1", Range("A1").End(xlDown))
        For i = 1 To ColumnCount
            ts.Write r.Offset(0, i - 1).Value & vbTab
            If i < ColumnCount Then ts.Write vbTab
        Next i
        ts.WriteLine
    Next r
    
    ts.Close
    Set fso = Nothing
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
To add an extra tab separator for everything except the last column, I'd guess. Whether that works or not is another question. Only you can decide that by inspecting the output text file and deciding if the format is to your liking.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,829
Messages
6,181,219
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top