VBA - Importing CSV File as Text removing LF and CR from String between Quotes before Importing


New Member
Oct 23, 2014
Hello Everyone,

I'm writing a Macro where I need to Import a CSV file as text where each line is not Delimited, but has a Fixed Width or is altogether. It also has to delete or not consider LF or CR that are between quotes before importing the data.

So basically I'm trying to put every line in one cell altogether not considering LF or CR within quotes.

I really appreciate any help!! Thanks!!

Here is my code so far:

Sub OldTable()

'Bring Old Table of a CSV File all information within One Column
Dim fNameAndPath As Variant
fNameAndPath = Application.GetOpenFilename(FileFilter:="All Files (*.CSV), *.CVS", Title:="Select Old Table")
If fNameAndPath = False Then Exit Sub
If fNameAndPath <> False Then
ActiveWorkbook.Worksheets.Add After:=Sheets(ActiveWorkbook.Sheets.Count)
ActiveSheet.Name = "Old Table"
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fNameAndPath _
, Destination:=Range("$A$1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2)
.TextFileTrailingMinusNumbers = False
.Refresh BackgroundQuery:=False
End With
End If

End Sub

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...