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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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