application Defined or object defined error

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try

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

Observe the dot before Cells(2,7)

M.
 
Upvote 0
The same here before Cells
Set rng = .Range("A1:G" & .Cells(.Rows.Count, 1).End(xlUp).Row)

M.
 
Upvote 0
Solution
Many thanks for pointing this out


Code now runs without any problem
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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