Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default "=" in text file formatting messes with my code loop- more elegant (and faster) solution?

I'm trying to get the following line of code to work;

mywrksht.Range(Usecol & CStr(rw)).Value = TotalDataArray(J, rw)

I'm parsing a text file and loading the data; it crashes on a value of "= =
="- three equals signs (although I added spaces between them here for
readability, I think they are sequential in the real file). Throughout the
file I'll get strings of various lengths of equal signs, depending on where
I'm parsing.

I can see why Excel doesn't like a cell starting with an equals sign when
the string doesn't work as a valid formula... on the other hand, I can't
control the formatting of the source document, so I'm stuck with what gets
pulled in. Throughout the document, rows of 'equals' symbols are used to
separate sections of the document. I can't throw a single apostrophe in
front of every incoming cell value, because I need many of the values as
numbers for later processing.

My less-elegant solution would be to check the Left(value, 1) to see if it
is an equals sign and add an apostrophe, but that adds a whole extra
calculation to each value I bring in. Is there a better way?

Thank you,
Keith


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default "=" in text file formatting messes with my code loop- more elegant (and faster) solution?

Did you format the cells as text? That seems to work.

Or if the array is a String rather than a Variant that seems to work with
General format.


--
Tim Zych
www.higherdata.com
Compare data in Excel and find differences with Workbook Compare
A free, powerful, flexible Excel utility


"ker_01" wrote in message
...
I'm trying to get the following line of code to work;

mywrksht.Range(Usecol & CStr(rw)).Value = TotalDataArray(J, rw)

I'm parsing a text file and loading the data; it crashes on a value of "=
= ="- three equals signs (although I added spaces between them here for
readability, I think they are sequential in the real file). Throughout the
file I'll get strings of various lengths of equal signs, depending on
where I'm parsing.

I can see why Excel doesn't like a cell starting with an equals sign when
the string doesn't work as a valid formula... on the other hand, I can't
control the formatting of the source document, so I'm stuck with what gets
pulled in. Throughout the document, rows of 'equals' symbols are used to
separate sections of the document. I can't throw a single apostrophe in
front of every incoming cell value, because I need many of the values as
numbers for later processing.

My less-elegant solution would be to check the Left(value, 1) to see if it
is an equals sign and add an apostrophe, but that adds a whole extra
calculation to each value I bring in. Is there a better way?

Thank you,
Keith



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default "=" in text file formatting messes with my code loop- more elegant(and faster) solution?

Maybe you could force that cell to be text:

mywrksht.Range(Usecol & rw).Value = "'" & TotalDataArray(J, rw)

or

with mywrksht.Range(Usecol & rw)
.numberformat = "@" 'text
.Value = TotalDataArray(J, rw)
end with

======

I like this format
mywrksht.cells(rw,usecol)....
when I have a row and column.

ker_01 wrote:

I'm trying to get the following line of code to work;

mywrksht.Range(Usecol & CStr(rw)).Value = TotalDataArray(J, rw)

I'm parsing a text file and loading the data; it crashes on a value of "= =
="- three equals signs (although I added spaces between them here for
readability, I think they are sequential in the real file). Throughout the
file I'll get strings of various lengths of equal signs, depending on where
I'm parsing.

I can see why Excel doesn't like a cell starting with an equals sign when
the string doesn't work as a valid formula... on the other hand, I can't
control the formatting of the source document, so I'm stuck with what gets
pulled in. Throughout the document, rows of 'equals' symbols are used to
separate sections of the document. I can't throw a single apostrophe in
front of every incoming cell value, because I need many of the values as
numbers for later processing.

My less-elegant solution would be to check the Left(value, 1) to see if it
is an equals sign and add an apostrophe, but that adds a whole extra
calculation to each value I bring in. Is there a better way?

Thank you,
Keith


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 209
Default "=" in text file formatting messes with my code loop- more ele

If you don't like any of Tim's great suggestions, you're going to have to
check each data element either when you try to put it into a cell...
mywrksht.Range(Usecol & CStr(rw)).Value
or when you first put it into your array...
TotalDataArray(J, rw)
and add an apostrophe at the beginning...
'===
--
Hope this helps.
If this post was helpfull, please remember to click on the ''''YES''''
button at the bottom of the screen.
Thanks,
Gary Brown


"Tim Zych" wrote:

Did you format the cells as text? That seems to work.

Or if the array is a String rather than a Variant that seems to work with
General format.


--
Tim Zych
www.higherdata.com
Compare data in Excel and find differences with Workbook Compare
A free, powerful, flexible Excel utility


"ker_01" wrote in message
...
I'm trying to get the following line of code to work;

mywrksht.Range(Usecol & CStr(rw)).Value = TotalDataArray(J, rw)

I'm parsing a text file and loading the data; it crashes on a value of "=
= ="- three equals signs (although I added spaces between them here for
readability, I think they are sequential in the real file). Throughout the
file I'll get strings of various lengths of equal signs, depending on
where I'm parsing.

I can see why Excel doesn't like a cell starting with an equals sign when
the string doesn't work as a valid formula... on the other hand, I can't
control the formatting of the source document, so I'm stuck with what gets
pulled in. Throughout the document, rows of 'equals' symbols are used to
separate sections of the document. I can't throw a single apostrophe in
front of every incoming cell value, because I need many of the values as
numbers for later processing.

My less-elegant solution would be to check the Left(value, 1) to see if it
is an equals sign and add an apostrophe, but that adds a whole extra
calculation to each value I bring in. Is there a better way?

Thank you,
Keith




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default "=" in text file formatting messes with my code loop- more elegant (and faster) solution?

Tim-

Thanks for the reply.

The problem is that the rest of the data file needs to be general format
(not forced to string, as the source file is something like (simplified):

==================
Title1 Title2 Title3 Title4
==================
13 19 4 17
15 0 0 14
12 16 7 28
==================
18 17 5 19
7 11 9 11
etc.

so I need to ignore the rows with the equals, and keep the rest as numbers
wherever possible (although the titles will default to text). In considering
my reply and how to explain the format, I've updated my code to check the
first character when loading each line (earlier in my code), so now my extra
calculations are down to one per row, rather than one per parsed value... a
30x improvement, although it still feels like an inelegant approach :)

Thanks again,
Keith

"Tim Zych" <tzych@NOSp@mE@RTHLINKDOTNET wrote in message
...
Did you format the cells as text? That seems to work.

Or if the array is a String rather than a Variant that seems to work with
General format.


--
Tim Zych
www.higherdata.com
Compare data in Excel and find differences with Workbook Compare
A free, powerful, flexible Excel utility


"ker_01" wrote in message
...
I'm trying to get the following line of code to work;

mywrksht.Range(Usecol & CStr(rw)).Value = TotalDataArray(J, rw)

I'm parsing a text file and loading the data; it crashes on a value of "=
= ="- three equals signs (although I added spaces between them here for
readability, I think they are sequential in the real file). Throughout
the file I'll get strings of various lengths of equal signs, depending on
where I'm parsing.

I can see why Excel doesn't like a cell starting with an equals sign when
the string doesn't work as a valid formula... on the other hand, I can't
control the formatting of the source document, so I'm stuck with what
gets pulled in. Throughout the document, rows of 'equals' symbols are
used to separate sections of the document. I can't throw a single
apostrophe in front of every incoming cell value, because I need many of
the values as numbers for later processing.

My less-elegant solution would be to check the Left(value, 1) to see if
it is an equals sign and add an apostrophe, but that adds a whole extra
calculation to each value I bring in. Is there a better way?

Thank you,
Keith







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default "=" in text file formatting messes with my code loop- more elegant (and faster) solution?

Thanks to Gary and Dave for your responses- they didnt show before I sent my
follow-up to Tim. Looks like lots of potential solutions.

I like this format
mywrksht.cells(rw,usecol)....


That looks simpler than what I always use...I'll give it a try!

Thanks,
Keith


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
text string: "91E10" in csv file auto converts to: "9.10E+11" [email protected] Excel Discussion (Misc queries) 2 August 12th 08 03:13 PM
"Growing" File Size: A Solution John Childs Excel Discussion (Misc queries) 0 July 23rd 07 02:08 AM
Find all cells NOT containing "100%" -no loop solution needed tskogstrom Excel Programming 2 November 25th 06 04:33 PM
Solution "Your changes could not be saved" "The document may be read-only or encrypted" [email protected] Excel Discussion (Misc queries) 0 August 7th 06 06:31 AM
Loop through ".DAT" files, open run code, close next Les Stout[_2_] Excel Programming 3 April 20th 06 10:15 AM


All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"