View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default opening text file in excel problem

Find one of those cells that looks like a date--but isn't.

Say it's in X9 (or whatever)
find an empty cell and put:
=len(x9)
to see what it returns.

If it's not 10 (dd/mm/yyyy has a length of 10), then there's other things in
that cell that don't belong--maybe that's what's causing the trouble with the
import.



jz193 wrote:

source is defineitly a txt file not csv-

Dave, appreicate your continued help on this- the len(x9) suggestion you
made I didn't really understand- would you be able to clarify that a bit?
thanks a lot.

"Dave Peterson" wrote:

What's the value of the variable Source?

If the name of that input file is *.csv, then excel will ignore your code for
each field.

If you find one of those offending cells (imported as text), what happens if you
use:

=len(x9)
(change the cell's address)

do you really get 10? dd/mm/yyyy



jz193 wrote:

I can;t see in my code where my specification of the format is actually- do I
need to add somethng to this (this is just a recorded macro) to do this?

Workbooks.OpenText FileName:= source, Origin _
:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=True, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1),
Array(7, 1), Array(8, 1), _
Array(9, 4), Array(10, 4), Array(11, 1), Array(12, 1), Array(13, 1),
Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1))

"Dave Peterson" wrote:

Are you sure you choose the correct format for that field? mdy, dmy, ...

I've never seen excel fail to convert something that looked like that kind of
date to a date (during the text import).

jz193 wrote:

hi- thanks for the tip. I have already done this- the only way it works once
the macros is finished is to manually go into the cell and press F2 and
return. Any other suggestions appreciated.

"Pete" wrote:

Do it manually and record a macro while you do it. Set the column
formats for Date DMY as appropriate. Then you will be able to merge
bits of the recorded macro into the macro you have already developed.

Hope this helps.

Pete



--

Dave Peterson


--

Dave Peterson


--

Dave Peterson