ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro error : Application-defined or object-defined error (https://www.excelbanter.com/excel-discussion-misc-queries/67413-macro-error-application-defined-object-defined-error.html)

Joe

Macro error : Application-defined or object-defined error
 
Hi,

I have a worksheet "Filtered OSMI". I want a macro to go through each
row, and if the entry in column D is less than 50, I want to delete
that row. The same process should run until I hit a blank cell in
column D. I tried the following macro, but it given the error
"Application-defined or object-defined error". Could you tell me what I
am missing here?

Sub OSMIvalcheck()

Dim c As Range 'current
Dim N As Range 'next
Dim dolval As Variant
Dim i As Variant

Set c = Worksheets("Filtered OSMI").Range("A2")

i = 2

Do While Not IsEmpty(c)
Sheets("Filtered OSMI").Select
dolval = Worksheets("Filtered OSMI").Cells(i, "D").Value
If dolval < 50 Then
Range(i, "D").EntireRow.Delete
Else
Set N = c.Offset(1, 0)
Set c = N
i = i + 1
End If
Loop
End Sub


Thanks,

Joe.


Dave Peterson

Macro error : Application-defined or object-defined error
 
How about:

Sub OSMIvalcheck()

Dim c As Range 'current
Dim dolval As Variant
dim delRng as range

Set c = Worksheets("Filtered OSMI").Range("D2")
Do While Not IsEmpty(c)
dolval = c.value
If dolval < 50 Then
if delrng is nothing then
set delrng = c
else
set delrng = union(c,delrng)
end if
end if
set c = c.offset(1,0)
Loop

if delrng is nothing then
'do nothing
else
delrng.entirerow.delete
end if

End Sub

Joe wrote:

Hi,

I have a worksheet "Filtered OSMI". I want a macro to go through each
row, and if the entry in column D is less than 50, I want to delete
that row. The same process should run until I hit a blank cell in
column D. I tried the following macro, but it given the error
"Application-defined or object-defined error". Could you tell me what I
am missing here?

Sub OSMIvalcheck()

Dim c As Range 'current
Dim N As Range 'next
Dim dolval As Variant
Dim i As Variant

Set c = Worksheets("Filtered OSMI").Range("A2")

i = 2

Do While Not IsEmpty(c)
Sheets("Filtered OSMI").Select
dolval = Worksheets("Filtered OSMI").Cells(i, "D").Value
If dolval < 50 Then
Range(i, "D").EntireRow.Delete
Else
Set N = c.Offset(1, 0)
Set c = N
i = i + 1
End If
Loop
End Sub

Thanks,

Joe.


--

Dave Peterson

Joe

Macro error : Application-defined or object-defined error
 
Thanks a lot, Dave .. I shall try this one, and give you the feedback.

-Joe.


Joe

Macro error : Application-defined or object-defined error
 
Runs perfect, Dave. thanks a bunch.

- Joe.



All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com