Text to Numbers

G

Guest

Hi,

!EndOffer = exc.Cells(i, 4).Value

EndOffer is defined as a Number and sometimes the cell, which is in a
external Excel spreadsheet, contines text ('n/a', etc) how do I change this
so that it is not a number I get the numeric zero

Thanks
 
R

RD

Hi,

!EndOffer = exc.Cells(i, 4).Value

EndOffer is defined as a Number and sometimes the cell, which is in a
external Excel spreadsheet, contines text ('n/a', etc) how do I change this
so that it is not a number I get the numeric zero

Thanks

Try:

If IsNumeric(exc.Cells(i, 4).Value) Then
!EndOffer = CInt(exc.Cells(i, 4).Value)
Else
!EndOffer = 0
End If

I cast the cell value as an integer but you can cast it as any numerical data
type. I actually use currency ( CCur(expression) ) a lot.

HTH,
RD
 
B

Baz

RD said:
Try:

If IsNumeric(exc.Cells(i, 4).Value) Then
!EndOffer = CInt(exc.Cells(i, 4).Value)
Else
!EndOffer = 0
End If

I cast the cell value as an integer but you can cast it as any numerical data
type. I actually use currency ( CCur(expression) ) a lot.

HTH,
RD

The Val function returns 0 if the argument is non-numeric
 

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