Hello,
I have data (numbers) in .txt files. I would like to import them into one worksheet as a numerical data, not as a text. I want the data to be in such format (MAKRO 1):
and I also would like to do it automatic in this way (MACRO 2)
How to combine MACRO 1 and 2 into ONE??
please help me if you would be so kind.
I have data (numbers) in .txt files. I would like to import them into one worksheet as a numerical data, not as a text. I want the data to be in such format (MAKRO 1):
Code:
Sub import()
Dim FilePath As String
FilePath = Application.GetOpenFilename("Text Files (*.txt),*.txt", , "Select Text File", , False)
If FilePath = "False" Then Exit Sub
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & FilePath, Destination:=Range("A1"))
.PreserveFormatting = True
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 852
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(8, 6, 7, 9, 6, 6, 9, 5, 7, 7)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.Delete
End With
End Sub
and I also would like to do it automatic in this way (MACRO 2)
Code:
Sub calosc()
Dim myDir As String, fn As String, txt As String, a(), n As Long, i As Long, ff As Integer
myDir = "c:\Arex2008\upper air sounding\Bodo\" '<- change here
fn = Dir(myDir & "*.txt")
Do While fn <> ""
ff = FreeFile
Open myDir & "\" & fn For Input As #ff
Do While Not EOF(ff)
Line Input #ff, txt
n = n + 1: ReDim Preserve a(1 To n)
a(n) = Split(txt, vbTab)
Loop
Close #ff
fn = Dir()
Loop
With ThisWorkbook.Sheets(1).Range("a1")
For i = 1 To n
.Offset(i - 1).Resize(, UBound(a(i)) + 1).Value = a(i)
Next
End With
End Sub
How to combine MACRO 1 and 2 into ONE??
please help me if you would be so kind.
Last edited: