ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Why is this a Type Mismatch error? (https://www.excelbanter.com/excel-programming/363670-why-type-mismatch-error.html)

Damon

Why is this a Type Mismatch error?
 
Can anybody please tell me why I am getting a type mismatch error on the
first line of this seemimgly simple bit of code? (i am using excell 2000)


Sub NAdelete()

If ActiveCell.Value = "#N/A" Then
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset(0, -1).EntireRow.Delete
Else
ActiveCell.Offset(0, 1).Activate
End If

End Sub

Thank you in advance!

Norman Jones

Why is this a Type Mismatch error?
 
Hi Damon,

Try replacing:

If ActiveCell.Value = "#N/A" Then


with

If ActiveCell.Text = "#N/A" Then


---
Regards,
Norman


"Damon" wrote in message
...
Can anybody please tell me why I am getting a type mismatch error on the
first line of this seemimgly simple bit of code? (i am using excell 2000)


Sub NAdelete()

If ActiveCell.Value = "#N/A" Then
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset(0, -1).EntireRow.Delete
Else
ActiveCell.Offset(0, 1).Activate
End If

End Sub

Thank you in advance!




Damon

Why is this a Type Mismatch error?
 
Thank you Norman that has fixed it!

"Norman Jones" wrote:

Hi Damon,

Try replacing:

If ActiveCell.Value = "#N/A" Then


with

If ActiveCell.Text = "#N/A" Then


---
Regards,
Norman


"Damon" wrote in message
...
Can anybody please tell me why I am getting a type mismatch error on the
first line of this seemimgly simple bit of code? (i am using excell 2000)


Sub NAdelete()

If ActiveCell.Value = "#N/A" Then
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset(0, -1).EntireRow.Delete
Else
ActiveCell.Offset(0, 1).Activate
End If

End Sub

Thank you in advance!





Mat P:son[_2_]

Why is this a Type Mismatch error?
 
However, instead of relying on string comparisons, you can also determine
what sort of data type you get back from the Value property, and if it's an
error you can take further action.

1) Check the Value (which is of type Variant) with VarType(...) = vbError,
or simply use IsError()

2) You can then use one of the constants from the XlCVError enumeration to
figure out exactly which error you've got.

Cheers,
/MP

"Damon" wrote:

Thank you Norman that has fixed it!

"Norman Jones" wrote:

Hi Damon,

Try replacing:

If ActiveCell.Value = "#N/A" Then


with

If ActiveCell.Text = "#N/A" Then


---
Regards,
Norman


"Damon" wrote in message
...
Can anybody please tell me why I am getting a type mismatch error on the
first line of this seemimgly simple bit of code? (i am using excell 2000)


Sub NAdelete()

If ActiveCell.Value = "#N/A" Then
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset(0, -1).EntireRow.Delete
Else
ActiveCell.Offset(0, 1).Activate
End If

End Sub

Thank you in advance!






All times are GMT +1. The time now is 03:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com