type mismatch help

cspengel

Board Regular
Joined
Oct 29, 2022
Messages
173
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have a list of percentages in column J. The actual cell itself contains a VLOOKUP formula which grabs them from another sheet, but shows the percentage it pulls. Column N contains another vlookup formula, which pulls either the letter "L" or the letter "R". What I am trying to do is loop through the rows and if for example row 2 column J contains the a percentage greater than 90% and column N row 2 contains the letter L, then delete that row. This code does delete stuff(and it seems to be correct), but I get a type mismatch error on

VBA Code:
If .Cells(x, 10).Value > 0.9 And .Cells(x, 14).Value = "L" Then

Here is the full code.

Thank you for any assistance.

VBA Code:
Sub DeletePlayers()
Dim x As Long

Application.ScreenUpdating = True
With ActiveSheet.UsedRange
For x = 2 To Rows.Count
If .Cells(x, 10).Value > 0.9 And .Cells(x, 14).Value = "L" Then
.Rows(x).EntireRow.Delete
x = x - 1
End If
Next x
End With
Application.ScreenUpdating = False
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Maybe it's because in the cells you have #N/A error.

In that case try the following code.

Notice that in the .rows.count instruction you must put the dote at the beginning, otherwise it will read all the rows of the sheet.
I highlighted the modified lines in the macro:

Rich (BB code):
Sub DeletePlayers()
  Dim x As Long
 
  Application.ScreenUpdating = True
  With ActiveSheet.UsedRange
    For x = .Rows.Count To 2 Step -1
      If Not IsError(.Cells(x, 10).Value) And Not IsError(.Cells(x, 14)) Then
        If .Cells(x, 10).Value > 0.9 And .Cells(x, 14).Value = "L" Then
          .Rows(x).EntireRow.Delete
        End If
      End If
    Next x
  End With
  Application.ScreenUpdating = False
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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