Vba - Copy data from .csv to .xlsx separating data in columns

mark84

New Member
Joined
Jan 22, 2021
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,
I d want to copy the data from a .csv file (named "Step1.csv") to another .xlsx file named Step2.xlsx (sheet "Output")
When I try to use vba code, it copies to the Step2.xlsx the data but with a wrong format, so all the fields are not separated in columns, but for each raw all the fields are in a cell, separated with ";".
Could you suggest me a vba code that copies the data from the .csv file to the .xlsx separating each field in a column?
I attach the two explamples: as is situation and to be situation.
Thanks in advance

Regards,
Marco
 

Attachments

  • as is_.png
    as is_.png
    11.2 KB · Views: 4
  • to be_.png
    to be_.png
    16.8 KB · Views: 5

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I've already attached an extract of the .csv file, it's a pic (as is_.png)

This is the code I used, but there is the problem I wrote before.


Sub From csv()
Dim WK1 As Workbook
Dim WK2 As Workbook
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim FileAltro As String
Application.ScreenUpdating = False

Set WK1 = ThisWorkbook
Set WK2 = Workbooks.Open("C:\Users\marco\Downloads\Step1.csv")

Set sh1 = WK1.Worksheets("Output")
Set sh2 = WK2.Worksheets("Step1")

sh2.Range("A:J").Copy
sh1.Range("A1").PasteSpecial Paste:=xlValues

Application.CutCopyMode = False
WK2.Close SaveChanges:=False

Application.ScreenUpdating = True
Close:
Set sh2 = Nothing
Set sh1 = Nothing
Set WK1 = Nothing
Set WK2 = Nothing
End Sub



Thanks in advance
 
Upvote 0
could someone try to help me please?
Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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