Need help using Text to Columns & Fieldinfo to parse columns with VBA in Excel

324 Views Asked by At

Per comments below, I'm editing my original posted question to more accurately reflect my problem.

This is for my job. In my work program, I download my data table to a csv file and it automatically opens the data in Notepad. I don't save the file in Notepad. (This process has to remain the same per my job. Saving the data is unnecessary and would take too much time as I have to do this same step hundreds of times a day.)

Once the data opens in Notepad, I copy all the data. I then need to paste the data directly into excel. The data is comprised of 66 different columns and includes headers. I need to parse the columns so that many of them are skipped, while most of the others are pasted as text. In the array below, i thought i laid that out correctly using the Array(1, 9), Array(4, 2) method, hoping Column 1 would be skipped and Column 4 would be pasted as text, etc...

When running this code though, the first column is skipped, but then all subsequent columns are pasted, not following any of the array setup i wrote in the code. I've researched questions on this site and many others. I can't figure what is wrong with my code to cause this issue.

Here is a link to the data I'm using (edited for anonymity of data): https://www.dropbox.com/s/2ujbpgm3zkvserx/Test_Data_Parsing.txt?dl=0

Here is the code I'm using:

    Sub Test_PasteParsing()


        With ThisWorkbook.Sheets(1)
                Range("A1").PasteSpecial
        End With


        Columns("A:A").TextToColumns _
                    Destination:=Range("A1"), _
                    DataType:=xlDelimited, _
                    TextQualifier:=xlDoubleQuote, _
                    ConsecutiveDelimiter:=True, _
                    Tab:=True, _
                    Semicolon:=False, _
                    Comma:=False, _
                    Space:=False, _
                    Other:=False, _
                    OtherChar:=False, _
                    FieldInfo:=Array(Array(1, 9), Array(2, 9), Array(3, 4), Array(4, 2), Array(5, 9), Array(6, 9), _
                        Array(7, 9), Array(8, 2), Array(9, 9), Array(10, 9), Array(11, 2), Array(12, 9), _
                        Array(13, 2), Array(14, 9), Array(15, 9), Array(16, 2), Array(17, 9), Array(18, 9), _
                        Array(19, 9), Array(20, 9), Array(21, 9), Array(22, 9), Array(23, 9), Array(24, 9), _
                        Array(25, 9), Array(26, 9), Array(27, 9), Array(28, 2), Array(29, 2), Array(30, 2), _
                        Array(31, 2), Array(32, 9), Array(33, 9), Array(34, 9), Array(35, 9), Array(36, 9), _
                        Array(37, 9), Array(38, 2), Array(39, 9), Array(40, 2), Array(41, 9), Array(42, 9), _
                        Array(43, 9), Array(44, 9), Array(45, 9), Array(46, 9), Array(47, 9), Array(48, 9), _
                        Array(49, 9), Array(50, 9), Array(51, 2), Array(52, 2), Array(53, 2), Array(54, 2), _
                        Array(55, 9), Array(56, 9), Array(57, 2), Array(58, 9), Array(59, 2), Array(60, 9), _
                        Array(61, 9), Array(62, 2), Array(63, 9), Array(64, 9), Array(65, 2), Array(66, 2)), _
                    TrailingMinusNumbers:=True


    End Sub

0

There are 0 best solutions below