Open a csv file but don't import all data and don't insert ""

TryingToLearn

Well-known Member
Joined
Sep 10, 2003
Messages
733
I'm trying to import all but the first 9 lines of a CSV. File opens and I can dump the 1st 9 lines but all data is enclosed in quotes. 1. How can I lose the quotes which are not in the CSV file?
2. Is there an easier way to skip the first x lines? TIA

i.e

"BKO 12/31 XXXXX47167 DEPOSIT *MOBILE ""300.00""4788.77"
[td width="15.1958%"]
1/2/2024​
[/td]​

VBA Code:
fName = Application.GetOpenFilename("C:\Users\owner\Documents\Finance\BOA\""Text Files (*.csv), *.csv")
If fName = "False" Then Exit Sub
Open fName For Input As #1
    rw = 1
If tst Then Stop
Do Until EOF(1)
START9:
    Line Input #1, linefromfile
    lineitems = split(linefromfile, ",") 'split on commas      
    For cl = 0 To UBound(lineitems)
    If rw < 9 Then
        cl = cl + 1
        rw = rw + 1
        GoTo START9:
    End If
    ActiveSheet.Cells(rw, cl + 1) = lineitems(cl)
    Next cl
    rw = rw + 1
    Loop
Close #1
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you have the comma as a List separator in the configuration

1728180575820.png

Then try simply opening the file:
VBA Code:
Sub opencsvfile()
  Dim fName As Variant
  Dim sh As Worksheet
  Dim lr As Long, lc As Long
  
  Set sh = ActiveSheet
  fName = Application.GetOpenFilename("C:\Users\owner\Documents\Finance\BOA\""Text Files (*.csv), *.csv")
  If fName = False Then Exit Sub
  
  Workbooks.Open (fName)
  lr = Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
  lc = Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious).Column
  If lr < 9 Then lr = 9
  Range("A9", Cells(lr, lc)).Copy sh.Range("A1")
  ActiveWorkbook.Close False
End Sub

----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0

Forum statistics

Threads
1,222,903
Messages
6,168,939
Members
452,227
Latest member
sam1121

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