Type mismatch error

deduwa

Board Regular
Joined
Jul 28, 2015
Messages
110
Hi,

I am getting a Type mismatch error of the below italic line. I cannot see where the problem is. Can anyone help (the macro goes down column Y and deletes entire row if cell in column Y is B or is C);

Last = Cells(Rows.Count, "A").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "Y").Value) = "B" Or (Cells(i, "Y").Value) = "C" Then
Cells(i, "A").EntireRow.Delete
End If
Next i
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Yes - I have #N/A in some cells.

I removed the #N/A's and the code worked.

Is there a way to get a msgbox so that instead of the macro not working, it still executes but the user sees that there are a number of N/A's that require further investigation?
 
Upvote 0
Something like
Code:
   last = Cells(Rows.Count, "A").End(xlUp).Row
   For i = last To 1 Step -1
      If IsError(Cells(i, "Y")) Then
         Msg = "Errors found"
      ElseIf (Cells(i, "Y").Value) = "B" Or (Cells(i, "Y").Value) = "C" Then
         Cells(i, "A").EntireRow.Delete
      End If
   Next i
   If Msg <> "" Then MsgBox Msg
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top