Ciao,
devo importare dei file di testo un po' particolari in Excel 2010 per cui devo utilizzare una macro.
Ho sfruttato la registrazione della macro che mi ha creato questo codice VBA:
codice:
Sub Macro1()
'
' Macro1 Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\NOME_FILE.txt", Destination:=Range("$A$1"))
.Name = "DISPL7"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 3
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileFixedColumnWidths = Array(5, 14)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
L'importazione funziona correttamente.
Ora il problema:
Il file contiente più insiemi di dati separati da un un testo (** END GRAPH **). Vorrei intercettare tale testo in modo che l'importazione interrompa l'accodamento e inizi a riposizionare i dati a fianco della terza colonna.
Esempio di dati:
codice:
15977 1.5976E+02 8.0880E-03
15978 1.5977E+02 8.0885E-03
15979 1.5978E+02 8.0890E-03
15980 1.5979E+02 8.0895E-03
15981 1.5980E+02 8.0900E-03
** END GRAPH **
1 0.0000E+00 0.0000E+00
2 1.0000E-02 1.3688E-05
3 2.0000E-02 1.3756E-05
4 3.0000E-02 1.3825E-05
5 4.0000E-02 1.3893E-05
6 5.0000E-02 1.3961E-05
7 6.0000E-02 1.4029E-05
8 7.0000E-02 1.4097E-05
9 8.0000E-02 1.4165E-05
10 9.0000E-02 1.4233E-05
11 1.0000E-01 1.4301E-05
** END GRAPH **
Grazie
ciao