Need to get rid of quotation marks when I save as .txt

Sargad_Strut

New Member
Joined
Mar 28, 2014
Messages
44
Hi guys,

So this is what my workbook does in short:
Opens up and updates a table from .accdb
Updates relevant data from an external source

I then need to save this data back into a text file to rewrite back into the database. The problem is that I'm getting "" at the start and end of every row in the txt file. Also tried to save it as .csv in which the quotation marks actually are not visible, but still there when I try to read the file back into the database.

2 Questions:
Does this happen because CellData is declared as a string?
Pretty obvious but, how can i solve this?

Thank you!


Part of my code:

Sub GenerateTextfile()

Dim FilePath As String
Dim CellData As String
Dim LastCol As Integer
Dim LastRow As Integer

LastCol = 4
LastRow = Blad2.Range("H2").Value

Blad2.Range("A2").Activate

CellData = ""

FilePath = "P:\Tobias\Update\<wbr>Output\NewData.txt"

Open FilePath For Output As #2

For i = 1 To LastRow
For j = 1 To LastCol
If j = LastCol Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + vbTab
End If
Next j
Write #2, CellData
CellData = ""
Next i

Close #2
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
2 Questions:
Does this happen because CellData is declared as a string?
Pretty obvious but, how can i solve this?

Part of my code:

Open FilePath For Output As #2

For i = 1 To LastRow
For j = 1 To LastCol
If j = LastCol Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + vbTab
End If
Next j
Write #2, CellData
CellData = ""
Next i

Close #2
End Sub
That is an artefact of the Write statement... try changing Write to Print and see if that produces the output you want.
 
Upvote 0
That's it, perfect!

For future reference, could you just briefly describe the difference between these two?

Thank you, you just made my day! :)
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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