View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
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