View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
okaizawa okaizawa is offline
external usenet poster
 
Posts: 129
Default Problem when hitting an empty cell

GPrabaka wrote:
I am running into a problem. I have the following code
dim counter as integer
counter = 0
Do While .ActiveCell.Offset(counter, 0).Value < ""
If .ActiveCell.Offset(counter, 22).Value < "" Then
.ActiveCell.EntireRow.Delete()
End If
counter = counter + 1
Loop
If .ActiveCell.Offset(counter,22) is empty, which should be valid, it
returns a fatal error "Cast from String "" to type 'Double' is not valid".
I have tried formatting that column to text, currency etc. I still hit the
same error.


your code seems to be written in VB.NET. if so, try

Do While Not IsNothing(.ActiveCell.Offset(counter, 0).Value)
If Not IsNothing(.ActiveCell.Offset(counter, 22).Value) Then

or

Do While CStr(.ActiveCell.Offset(counter, 0).Value) < ""
If CStr(.ActiveCell.Offset(counter, 22).Value) < "" Then

--
HTH,

okaizawa