Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default "value" works in sheet, not vba

Either check for the error:

if iserror(range("c13").value) then
'do what an error would do
else
if range("c13").value = "BOCES" then
'do ...
end if
end if


or use the .text property:

if range("c13").text = "BOCES" then



"EnigmaCDE <" wrote:

I am having trouble referencing a cell (or range) .value property from a
cell that is returning #N/A (Error 2042) as a result of a failed
formula. The following code fails (sometimes):

If Range("C13").value = "BOCES" THEN
....
END IF

Cell C13 has a VLookup formula that sometimes returns #N/A instead of a
valid lookup value. Oddly enough when the lookup is successful then
the content of Cell C13 is "text" and the code works. However, when
the formula is unsuccessful then it returns #N/A (Error 2042) which is
an "error object" instead of "text". Consequently my code raises an
"error 13 - type mismatch". I'm suprised to find a function that can
change it's return type on the fly.

Anyway here is how I was able to make it work.

Dim MyValue as variant
MyValue = Range("C13").value
if MyValue = "BOCES" THEN
...
END IF

Does anyone have a better way to get around this problem????

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

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
How do i enable "Group" & "Ungroup" in a protected sheet DBLA137 Excel Discussion (Misc queries) 1 March 11th 09 12:20 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Excel "Move or Copy" and "Delete" sheet functions dsiama Excel Worksheet Functions 1 December 28th 07 01:57 PM
How do i enable "Group" & "Ungroup" in a protected sheet ruddojo Excel Discussion (Misc queries) 0 June 2nd 06 01:01 AM
Range only works when Sheet Name is "Sheet1" paul reed Excel Programming 4 September 14th 03 08:37 PM


All times are GMT +1. The time now is 01:12 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"