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

Sargad_Strut

New Member
Joined
Mar 28, 2014
Messages
39
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
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,857
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Sargad_Strut

New Member
Joined
Mar 28, 2014
Messages
39
That's it, perfect!

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

Thank you, you just made my day! :)
 

Watch MrExcel Video

Forum statistics

Threads
1,127,093
Messages
5,622,664
Members
415,917
Latest member
kungsleden

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
Top