│ seperator in text file

jakobt

Active Member
Joined
May 31, 2010
Messages
337
I want to save a excel table to a text file and each cell must be separated by│in the text file?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I want to save a excel table to a text file and each cell must be separated by│in the text file?
Is each row to be a separate line in the text file or do you want one humongous line containing all of the cell values?

How many columns are there? If the number is not fixed, what is the maximum number of columns you might anticipate?

How many rows maximum would you expect there to be?
 
Upvote 0
The sheet has 30 rows and 30 columns. But this is a generic issue, so in principle it can be something else.
 
Upvote 0
The sheet has 30 rows and 30 columns. But this is a generic issue, so in principle it can be something else.
You did not answer the first question I asked, so I'll assume you want each row on its own line within the outputted file. I have assumed your data starts in cell A1... you need to change the red highlighted text to the path/filename for the outputted file.
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub MakeTextWithVerticalBarDelimiter()
  Dim R As Long, LastRow As Long, LastCol As Long, FF As Long
  Dim PathFilename As String, Result As String
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  For R = 1 To LastRow
    LastCol = Cells(R, Columns.Count).End(xlToLeft).Column
    Result = Result & vbNewLine & Join(Application.Index(Cells(R, 1).Resize(, LastCol).Value, 1, 0), "|")
  Next
  PathFilename = "[B][color="#FF0000"]c:\temp\test.txt[/COLOR][/B]"
  FF = FreeFile
  Open PathFilename For Output As [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF"]#FF[/URL] 
    Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF"]#FF[/URL] , Mid(Result, Len(vbNewLine))
  Close [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF"]#FF[/URL] 
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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