Hello,
I have written a macro that will import 4 different text files into 1 excel worksheet.
After each import i append an ID(5th column) to distingush the source of the data.
My problem is how to make sure that it always imports starting from the next free cell & to make sure it appends the ID correctly.
Here is what i have for now:
Thanks in anticipation
I have written a macro that will import 4 different text files into 1 excel worksheet.
After each import i append an ID(5th column) to distingush the source of the data.
My problem is how to make sure that it always imports starting from the next free cell & to make sure it appends the ID correctly.
Here is what i have for now:
Code:
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\WK44.Net\LAG\MFS_list.csv" _
, Destination:=Range("A1"))
.Name = "MFS_list_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Range("A2").Select
Selection.End(xlToRight).Select
Range("E2").Select
ActiveCell.FormulaR1C1 = "1"
Range("E2").Select
Selection.Copy
Range("E3:E6").Select
ActiveSheet.Paste
Range("A7").Select
Application.CutCopyMode = False
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\WK44.Net\IBD\MFS_list.csv" _
, Destination:=Range("A7"))
.Name = "MFS_list_2"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Selection.End(xlToRight).Select
Range("E8").Select
ActiveCell.FormulaR1C1 = "2"
Range("E9").Select
ActiveCell.FormulaR1C1 = "2"
Range("A1").Select
Selection.End(xlDown).Select
Range("A10").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\WK44.Net\BEN\MFS_list.csv" _
, Destination:=Range("A10"))
.Name = "MFS_list_3"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Selection.End(xlToRight).Select
Range("E11").Select
ActiveCell.FormulaR1C1 = "3"
Range("A1").Select
Selection.End(xlDown).Select
Range("A12").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\WK44.Net\ABJ\MFS_list.csv" _
, Destination:=Range("A12"))
.Name = "MFS_list_4"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Selection.End(xlToRight).Select
Range("E13").Select
ActiveCell.FormulaR1C1 = "4"
Range("E14").Select
ActiveCell.FormulaR1C1 = "4"
Range("A1").Select
End Sub
Comment