Import CSV data - newbie question

JeppeML

New Member
Joined
Apr 12, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi forum
I am trying to import data from a semi colon delimited csv file.
1st attempt, i discovered that excel assumed that the delimiter was ","
trying to correct this, i get an syntax error, or a compile error "expected; end of statement" -- marking the "," after the filepath.
The videos/posts I've found writes the code as I do, but is not getting any errors - Anyone knows what I'm overseeing?
Thanks in advance - Jeppe

VBA Code:
Sub get_data()

 

Dim Wb1 As Workbook

Application.ScreenUpdating = False

Set Wb1 = Workbooks.Open("C:\xxxxxx\Varmeprognose.csv"), DataType:= xlDelimited, Semicolon:= True, DecimalSeparator:= ",", ThousandsSeparator:="."

Wb1.Sheets(1).Range("A1:C200").Copy

Wb1.Close SaveChanges:=False

Application.ScreenUpdating = True

Range("A1").Select
ActiveSheet.Paste
 

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi @JeppeML.
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.​

You have problems in that Open method:
1685621701050.png


---------------------------
Please do the following:

1) Check the List separator settings:

On Windows, you'll find this setting at:​
Control Panel > Region & Language > Additional settings > Change date, time, or number formats > additional settings​
Windows advanced regional settings button
Type a semicolon into the List separtor box:​
1685621859573.png
Click OK Twice to confirm the change.​

2. Use the following code:
Note: Just update the path.​
VBA Code:
Sub get_data()
  Dim Wb1 As Workbook
  
  Application.ScreenUpdating = False
  Set Wb1 = Workbooks.Open(Filename:="C:\xxxxxx\Varmeprognose.csv", Local:=True)
  Wb1.Sheets(1).Range("A1:C200").Copy ThisWorkbook.ActiveSheet.Range("A1")
  Wb1.Close SaveChanges:=False
  Application.ScreenUpdating = True
End Sub



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

Forum statistics

Threads
1,215,140
Messages
6,123,269
Members
449,093
Latest member
Vincent Khandagale

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