Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Help on Code Snippet Error {Val function}


Hi

I have a test on a cell which is used on a large block of data that can
contain any items e.g. text numbers, formulae etc as follows

Val(.Cells(iFirstDataRow, iTestCol))

When I use it I get an overflow error when the cell contains ("13 E04 01")

When I change the text value
?Val("13 G04 01")
returns 13

What is being computed in the overflow-errored case?

Thanks for any help

Tim

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default Help on Code Snippet Error {Val function}

"Tim Childs" wrote:
I have a test on a cell which is used on a large block of data that can
contain any items e.g. text numbers, formulae etc as follows
Val(.Cells(iFirstDataRow, iTestCol))

When I use it I get an overflow error when the cell contains ("13 E04 01")
When I change the text value
?Val("13 G04 01")
returns 13

What is being computed in the overflow-errored case?


Might be a coincidence. What are the values of iFirstDataRow and iTestCol
when you get the error?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Help on Code Snippet Error {Val function}

1 and 58

I thought the E04 was generating an exponential or something?

bw, Tim

"joeu2004" wrote in message
...
"Tim Childs" wrote:
I have a test on a cell which is used on a large block of data that can
contain any items e.g. text numbers, formulae etc as follows
Val(.Cells(iFirstDataRow, iTestCol))

When I use it I get an overflow error when the cell contains ("13 E04
01")
When I change the text value
?Val("13 G04 01")
returns 13

What is being computed in the overflow-errored case?


Might be a coincidence. What are the values of iFirstDataRow and iTestCol
when you get the error?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default Help on Code Snippet Error {Val function}

"Tim Childs" wrote:
I thought the E04 was generating an exponential or something?


Almost right.

I did not notice the difference between "13 E04 01" and "13 G04 01".

Note that Val("13 45") is interpreted as Val("1345"). That is, Val ignores
spaces.

So the problem is: Val interprets "13 E04 01" as "13E401". That is indeed
an overflow insofar as it exceeds 1.79769313486232E+308 = (2^1023 -
2^(1023-53))*2.

If you want Val to stop on the first interstitial space, try:

Val(Replace(LTrim(RTrim(.Cells(iFirstDataRow, iTestCol))," ",","))

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Help on Code Snippet Error {Val function}

hi

thks for that, and the suggested workaround. Very helpful
Tim

"joeu2004" wrote in message
...
"Tim Childs" wrote:
I thought the E04 was generating an exponential or something?


Almost right.

I did not notice the difference between "13 E04 01" and "13 G04 01".

Note that Val("13 45") is interpreted as Val("1345"). That is, Val
ignores spaces.

So the problem is: Val interprets "13 E04 01" as "13E401". That is
indeed an overflow insofar as it exceeds 1.79769313486232E+308 = (2^1023 -
2^(1023-53))*2.

If you want Val to stop on the first interstitial space, try:

Val(Replace(LTrim(RTrim(.Cells(iFirstDataRow, iTestCol))," ",","))




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default Help on Code Snippet Error {Val function}

After-thought.... I wrote:
Val(Replace(LTrim(RTrim(.Cells(iFirstDataRow, iTestCol))," ",","))


RTrim is not necessary. Simply:

Val(Replace(LTrim(.Cells(iFirstDataRow, iTestCol))," ",","))

(Hmm, also corrects a copy-and-paste typo in the original expression.)

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Help on Code Snippet Error {Val function}

Jo
thanks for your help
Tim

"joeu2004" wrote in message
...
After-thought.... I wrote:
Val(Replace(LTrim(RTrim(.Cells(iFirstDataRow, iTestCol))," ",","))


RTrim is not necessary. Simply:

Val(Replace(LTrim(.Cells(iFirstDataRow, iTestCol))," ",","))

(Hmm, also corrects a copy-and-paste typo in the original expression.)


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
Want to modify this VBA code snippet joel Excel Programming 1 April 8th 09 08:46 PM
Want to modify this VBA code snippet Sam Commar Excel Programming 1 April 5th 09 01:50 PM
Problem in WITH/END WITH code snippet [email protected] Excel Programming 2 January 21st 06 02:59 PM
Code snippet storage Ken McLennan[_3_] Excel Programming 9 August 20th 04 03:25 PM


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

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

About Us

"It's about Microsoft Excel"