BIGTONE559
Active Member
- Joined
- Apr 20, 2011
- Messages
- 336
I'm trying to figure out how to prompt a file for import as an external data source and then when it is imported into cell $A$1 then sort it.
Tried recording the macro but no luck in understanding it.
this is what i received when i recorded the macro. If someone wouldn't mind simplifying it or potentially showing me another way i'd appreciate it.
Thanks
Tried recording the macro but no luck in understanding it.
this is what i received when i recorded the macro. If someone wouldn't mind simplifying it or potentially showing me another way i'd appreciate it.
Thanks
Code:
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;\\Master01\C\EmpFile\Checktest.txt", Destination:=Range("$A$1"))
.Name = "Checktest"
.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 = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Range("F1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("YTDdb").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("YTDdb").Sort.SortFields.Add Key:=Range("F1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("YTDdb").Sort
.SetRange Range("A1:G30144")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub