application Defined or object defined error

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,994
Office Version
  1. 2019
Platform
  1. Windows
I have the following code to delete rows where the value in Col G > 1


when running the macro, I get run time error "application-Defined or object-defined error" and the code below is highlighted


Code:
  With Cells(2, 7).Resize(rng.Rows.Count - 1)


See full code below

Code:
 Sub DelReconItemsGreaterthan1()

Application.ScreenUpdating = False
 Dim rng As Range, lr As Long
 
        With Sheets("reconciling items")
        
           lr = .Cells(.Rows.Count, "A").End(xlUp).Row
           If .Range("A2") = "" Then
            
           Exit Sub
                               Else
              End If
             
           
           
Set rng = .Range("A1:G" & Cells(.Rows.Count, 1).End(xlUp).Row)
    With Cells(2, 7).Resize(rng.Rows.Count - 1)
        .FormulaR1C1 = "=COUNTIF(R2C6:R" & lr & "C6,RC[-1])"
        
         '.Formula = "=COUNTIF(R2C6:R11C6,RC[-1])"
        .Value = .Value
    End With
    With rng
        .AutoFilter 7, "> 1"
            .Offset(1).EntireRow.Delete
        .AutoFilter
    End With
        End With
        
    Sheets("reconciling items").Select
    
Columns(7).Delete
 
End Sub

It would be appreciated if someone could kindly amend my code
 

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.

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,868
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Try

With .Cells(2, 7).Resize(rng.Rows.Count - 1)

Observe the dot before Cells(2,7)

M.
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,868
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
The same here before Cells
Set rng = .Range("A1:G" & .Cells(.Rows.Count, 1).End(xlUp).Row)

M.
 
Solution

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,994
Office Version
  1. 2019
Platform
  1. Windows
Many thanks for pointing this out


Code now runs without any problem
 

Forum statistics

Threads
1,141,817
Messages
5,708,760
Members
421,588
Latest member
Wawie

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