ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Issue with parsing text file into worksheet (https://www.excelbanter.com/excel-programming/330141-issue-parsing-text-file-into-worksheet.html)

primrose

Issue with parsing text file into worksheet
 

Hello,

I have a sub function that goes to a shared drive to grasp a text file,
open it and parse it into a worksheet using Delimited. After that, I
call a macro that uses "TextToColumns" to parse the column of cells
from that worksheet into several columns using FixedWidth. I noticed
that the first few digits of some numbers were cut off and put into
next cells. To fix it, I went to my codes and manually changed
character widths for the columns (arrays below) and it worked for that
day. However, the next day, when a new text file comes, the numbers
are cutt off again.

Is there any way to fix this problem? It’s not efficient to manually
change code everyday. I apreciate any idea/help. Thanks!

Here is my code.

Range("A" & RowNumber & ":A" & RowNumber + 1000).Select

Selection.TextToColumns Destination:=Range("A" & RowNumber & ":A" &
RowNumber + 400), DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 1), Array(11, 1), Array(24, 1),
Array(34, 1), Array(50, 1),
Array(65, 1), Array(79, 1), Array(93, 1), Array(105, 1),
Array(119, 1), Array(132, 1),
Array(147, 1), Array(161, 1), Array(175, 1), Array(187, 1),
Array(202, 1), Array(215, 1),
Array(230, 1), Array(244, 1), Array(257, 1), Array(270, 1)),
TrailingMinusNumbers:= True


--
primrose
------------------------------------------------------------------------
primrose's Profile: http://www.excelforum.com/member.php...o&userid=23716
View this thread: http://www.excelforum.com/showthread...hreadid=373898


anilsolipuram[_22_]

Issue with parsing text file into worksheet
 

what type of data is it.

I think fixed width is not a correct option for using text to columns.

for fixedwidth all the rows should have same width between fields.

can you paste or attach sample content.


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=373898



All times are GMT +1. The time now is 01:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com