PDA

View Full Version : How to remove cells leading ' s when cvs (comma separated) file is imported in Excel.



mikeburg
01-09-2016, 10:57 AM
I need to find out how to remove leading ' (apostophes) that is in each cell that I imported into excel from a cvs file (comma separated).

They happen every time I import a cvs (comma separated) file.

Thank you for any help you can give me.
mikeburg

p45cal
01-09-2016, 11:50 AM
perhaps attach said cvs file and outline steps you take to import

GarysStudent
01-10-2016, 01:09 PM
This may give you a start:


Sub CSVspecial()
Dim FilesToOpen As String, TextLine As String
Dim i As Long, j As Long, a As Variant

FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Text Files (*.csv), *.csv", Title:="Text Files to Open")
Close #1
Open FilesToOpen For Input As #1
j = 1
Do While Not EOF(1)
Line Input #1, TextLine
ary = Split(TextLine, ",")
i = 1
For Each a In ary
If Left(a, 1) = "'" Then a = Mid(a, 2)
Cells(j, i) = a
i = i + 1
Next a
j = j + 1
Loop
Close #1
End Sub

Paul_Hossler
01-10-2016, 02:00 PM
They happen every time I import a cvs (comma separated) file.

In every cell in every file?

Attach a sample (small) CSV file so we can see