Home » excel » excel – Reworked a text file with vba

excel – Reworked a text file with vba

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a text file, I imported it into excel thanks to vba now I would like to remove the first column and the first 9 rows. You think it’s possible to do that by rewriting the following code

      With ActiveSheet.QueryTables.Add(Connection:= _
     "TEXT;" & fpath & "\" & ffilename, Destination:=Range("$A$1"))
     .Name = "text"
     .FieldNames = True
     .RowNumbers = False
     .FillAdjacentFormulas = False
     .PreserveFormatting = True
     .RefreshOnFileOpen = False
     .RefreshStyle = xlInsertDeleteCells
     .SavePassword = False
     .SaveData = True
     .AdjustColumnWidth = True
     .RefreshPeriod = 0
     .TextFilePromptOnRefresh = False
     .TextFilePlatform = 850
     .TextFileStartRow = 1
     .TextFileParseType = xlDelimited
     .TextFileTextQualifier = xlTextQualifierDoubleQuote
     .TextFileConsecutiveDelimiter = False
     .TextFileTabDelimiter = True
     .TextFileSemicolonDelimiter = False
     .TextFileCommaDelimiter = False
     .TextFileSpaceDelimiter = False
     .TextFileOtherDelimiter = "|"
     .TextFileColumnDataTypes = Array(1)
     .TextFileTrailingMinusNumbers = True
     .Refresh BackgroundQuery:=False
 End With

Example

How to&Answers:

You can add after that statement something to delete the ranges you want

With ActiveSheet
    .Columns(1).EntireColumn.Delete 'delete first column
    .Rows("1:9").EntireRow.Delete 'delete first 9 rows
End With