Text returned as 0

C

Chris

Hi,

I've having various problems with my VBA functions, and
came to writing this test functoin to see what the .Text
property is set to:

Function GetText(IRange As Range) As Long
If (Not IsEmpty(cl)) Then
GetText = IRangeText
End If
End Function

(My column A is a list of numbers)
I called this function from the correct spreadsheet
with "A2" (without the speech marks) as the argument. The
visible contents of the cell is "761", but the function
returned "0". I cannot figure out why this is happening.
(I know the range is valid as well)

(Replacing .Text with .Value makes no difference).

Thanks in advance,
Chris
 
D

Dave Peterson

Did you really have:
GetText = IRange.Text
??

And you said you wanted to return a long.
Function GetText(IRange As Range) As Long
(I think I'd use a Variant so I could use it with non-numeric cells).

And you check: Isempty(c1)
Didn't you mean: if (not isempty(irange)) then

And just curious, why not:
=a1
or
=if(a1="","",a1)


This worked ok for me:

Option Explicit
Function GetText(IRange As Range) As Variant
Set IRange = IRange(1)
If (Not IsEmpty(IRange)) Then
GetText = IRange.Text
Else
GetText = ""
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top