Text to Numbers

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Back
Top