Hi,
found the this code:
How to modify the vba code below to import the data into an existing spreadsheet to specific columns in that spreadsheet instead creating a new file:
thank you
found the this code:
How to modify the vba code below to import the data into an existing spreadsheet to specific columns in that spreadsheet instead creating a new file:
VBA Code:
Sub CSV_to_XLSX_Add_Columns()
' ### 23 Apr. 2019 oAnast ###
Dim mywb As Workbook, wb As Workbook
Dim sh As Worksheet
Set mywb = ThisWorkbook
Dim vFile
Dim fn
Dim x As Integer, t As Integer
Dim v As Variant, vName As Variant
v = Array(117, 113, 121) ' ## EXPORT COLUMNS ##
vFile = Application.GetOpenFilename("CSV Files(*.csv),*.csv", , "please select a file", MultiSelect:=False)
If vFile = False Then Exit Sub
vName = Split(vFile, "\")
vName = Replace(vName(UBound(v)), ".csv", "")
Application.ScreenUpdating = False
Set sh = mywb.Sheets.Add(before:=mywb.Sheets(1))
sh.Name = vName
Workbooks.OpenText Filename:=vFile, Local:=True
Set wb = ActiveWorkbook
t = 1
For x = 0 To UBound(v)
wb.Sheets(1).Columns(v(x)).Copy sh.Cells(1, t)
t = t + 1
Next
sh.UsedRange.EntireColumn.AutoFit
wb.Close False
fn = Environ("USERPROFILE") & "\Desktop\" & vName & ".xlsx"
sh.Copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs fn
ActiveWorkbook.Close False
sh.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
thank you