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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,224,808
Messages
6,181,072
Members
453,020
Latest member
mattg2448

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