Macro to insert IF "A" or "B" Then Do "C" - Not Working (Run-time error 13: Type Mismatch)

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Any thoughts why my If .value = "A" or "B" then statement isn't working?

Code:
Sub Remove_CorrNeg_Transaction_Entries()
    Dim Dest_Firstrow As Long
    Dim Dest_Lastrow As Long
    Dim lRow As Long
    Dim CalcMode As Long
    Dim ViewMode As Long
    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    'We use the ActiveSheet but you can replace this with
    'Sheets("MySheet")if you want
    With Sheets("Inventory Transaction Summary -")
        'We select the sheet so we can change the window view
        .Select
        'If you are in Page Break Preview Or Page Layout view go
        'back to normal view, we do this for speed
        ViewMode = ActiveWindow.View
        ActiveWindow.View = xlNormalView
        'Turn off Page Breaks, we do this for speed
        .DisplayPageBreaks = False
        'Set the first and last row to loop through
        LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
        'We loop from Lastrow to Firstrow (bottom to top)
        For lRow = LastRow To 1 Step -1
            'We check the values in the L column in this example
            With .Cells(lRow, "AH")
                If Not IsError(.Value) Then
                    If .Value = "GBA040" Or "GBA041" Then .EntireRow.Delete
                    'This will delete each row with the Value "delete"
                    'in Column L, case sensitive.
                End If
            End With
        Next lRow
    End With
    ActiveWindow.View = ViewMode
    With Application
        .ScreenUpdating = True
        .Calculation = CalcMode
    End With
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
Office Version
  1. 365
Platform
  1. Windows
If you mean this part of the code,
Code:
                If Not IsError(.Value) Then
                    If .Value = "GBA040" Or "GBA041" Then .EntireRow.Delete
                    'This will delete each row with the Value "delete"
                    'in Column L, case sensitive.
                End If
it should be this.
Code:
                If Not IsError(.Value) Then
                    If .Value = "GBA040" Or .Value = "GBA041" Then .EntireRow.Delete
                    'This will delete each row with the Value "delete"
                    'in Column L, case sensitive.
                End If
 

Watch MrExcel Video

Forum statistics

Threads
1,130,336
Messages
5,641,565
Members
417,222
Latest member
Broflovski

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
Top