Issue with parsing text file into worksheet

P

primrose

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
 
A

anilsolipuram

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top