Application-defined or object-defined error

Heather_Llo

New Member
Joined
Feb 16, 2018
Messages
17
Hi,

I am getting said error on this line:
.EntireRow.Cut Destination:=Sheets("Need to E-mail").Range("B" & Rows.Count).End(xlUp).Offset(1, -2)
Of this macro:
Sub NeedEmail()Dim LR As Long, i As Long
With Sheets("Working")
LR = .Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With .Range("B" & i)
If .Value Like "*Interested*" Then .EntireRow.Cut Destination:=Sheets("Need to E-mail").Range("B" & Rows.Count).End(xlUp).Offset(1, -2)
End With
Next i
End With
End Sub
That I jacked from this topic: https://www.mrexcel.com/forum/excel-questions/685654-simple-macro-cut-paste-based-cell-value.html

I am wondering if anyone can help me to diagnose the problem. I'm new to Excel and not entirely sure what I'm doing. Learning steadily but slowly.

Thanks!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
this
Code:
.Offset(1, -2)
is trying to offset 2 columns to the left, but as you are looking at col B, you can only offset 1 column left.
What are you trying to do?
 
Upvote 0
Changing that to -1 worked, thank you so much! Simple errors due to my simple misunderstanding, lol.

I am cutting any row in sheet "Working" that has "Need to E-mail" in Column B and pasting it into the next blank row on a new sheet called "Need to E-mail".

Since this is working now, I have another question: How can I modify the code to delete the blank rows after I've cut their content? Should I just record a macro where I filter on blank rows and delete them that way?
 
Upvote 0
I'd tend to do it like this
Code:
Sub NeedEmail()
   Dim LR As Long, i As Long
   Dim Rng As Range
   
   With Sheets("Working")
      LR = .Range("B" & Rows.Count).End(xlUp).Row
      For i = 1 To LR
         If .Range("B" & i).Value Like "*Interested*" Then
            .Rows(i).Copy Sheets("Need to E-mail").Range("B" & Rows.Count).End(xlUp).Offset(1, -1)
            If Rng Is Nothing Then
               Set Rng = .Range("A" & i)
            Else
               Set Rng = Union(Rng, .Range("A" & i))
            End If
         End If
      Next i
   End With
   If Not Rng Is Nothing Then Rng.EntireRow.Delete
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,684
Messages
6,126,199
Members
449,298
Latest member
Jest

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