Il problema che ho riscontrato è che se il file .csv lo apro manualmente da esplorare risorse, ottengo una visualizzazione con i delimitatori di campo applicati (Foto 1), se il file lo apro utilizzando visualbasic (procedendo passo passo con f8 per vedere il comportamento della macro), il file viene aperto come riportato nella seconda foto.
Buongiorno a te,
si può fare, ma devo vedere il tuo codice, potresti dover avere bisogno di rivedere il processo di import.
Ciao.
P.S. magari anche qualche riga del csv aiuterebbe a contestualizzarti la risposta, puoi condividere il file denaturato da dati sensibili?
Grazie EleuterioTedeschi,
di seguito il codice della macro:
_______________________________________________________________________
Sub OpenNewBox()
Dim xFilePath As String
Dim xObjFD As FileDialog
Set xObjFD = Application.FileDialog(msoFileDialogFilePicker)
With xObjFD
.AllowMultiSelect = False
9 .Filters.Add "Excel Files", "*.csv", 1
.Show
If .SelectedItems.Count > 0 Then
xFilePath = .SelectedItems.Item(1)
Else
Exit Sub
End If
End With
Workbooks.Open xFilePath
' Apri ArchivioRCE0
Worksheets("ArchivioRCE0").Activate
Range("A1").Select
'
' Sistemazione colonne
'
Range("C2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=IF(RC[-2]>1,CONCATENATE(RC[-2],"","",RC[-1]),)"
Range("C2").Select
Selection.Copy
Columns("C:C").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks \_
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, \_
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, \_
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo \_
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), \_
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 \_
), Array(14, 1), Array(15, 1), Array(16, 1)), TrailingMinusNumbers:=True
Columns("A:C").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
'
' Elimina colonne non utilizzate
'
Range("B:B,E:N,P:P").Select
Range("P1").Activate
Selection.Delete Shift:=xlToLeft
'
' Ordina decrescente
'
Range("A1").Select
ActiveWorkbook.Worksheets("ArchivioRCE0").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ArchivioRCE0").Sort.SortFields.Add Key:=Range( \_
"A2:A300000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= \_
xlSortNormal
With ActiveWorkbook.Worksheets("ArchivioRCE0").Sort
.SetRange Range("A1:E300000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'
' Converte testo RCE/CAB
'
Columns("C:C").Select
Selection.Replace What:="34", Replacement:="RCE", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
Selection.Replace What:="33", Replacement:="CAB", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
'
' Converte testo +/-
'
Columns("B:B").Select
Selection.Replace What:="0", Replacement:=" -", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
Selection.Replace What:="1", Replacement:=" +", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
Selection.Replace What:="2", Replacement:=" -", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
Selection.Replace What:="3", Replacement:=" +", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
Selection.Replace What:="6", Replacement:=" R", LookAt:=xlPart, \_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, \_
ReplaceFormat:=False
'
' Converti tempo
'
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/1000000"
Range("B2").Select
Selection.Copy
Range("B3:B300000").Select
ActiveSheet.Paste
Columns("B:B").Select
Application.CutCopyMode = False
Selection.Copy
Columns("A:A").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= \_
xlNone, SkipBlanks:=False, Transpose:=False
Columns("A:A").Select
Application.CutCopyMode = False
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss.000"
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
ActiveCell.FormulaR1C1 = "TimeStm"
Range("A2").Select
'
' Elimina intestazione colonna + e RCS/CAB
'
Range("B1:C1").Select
Selection.ClearContents
'
' Adatta larghezza colonna
'
Columns("A:E").Select
Columns("A:E").EntireColumn.AutoFit
'
'
' Blocca finestra
'
Range("A1").Select
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
'
' Copia su Analisi RCE
'
Columns("A:D").Select
Selection.Copy
Windows("Analisi RCE\_.xlsm").Activate
Range("A1").Select
ActiveSheet.Paste
'
' Applica filtro
'
Cells.Select
Selection.AutoFilter
' Chiudi Archivio RCE0
Workbooks("ArchivioRCE0.csv").Close SaveChanges:=False
End Sub
_______________________________________________________________________
Questo è il codice fatto per "bypassare" il problema, ma applicato a 300.000 celle inizia a diventare pesante.
DI seguito, link per scaricare il .csv, alleggerito di qualche riga.
https://we.tl/t-9VBt8ZEw0v