Trying to delete a range with VBA - not working

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
I need to delete a range and I want to preserve the cells around it, so deleting all of the rows is not an option at this point.


So far, my research has shown that you can only delete an entire row. You can shift the cells up or to the left, but I have found nothing that shows how you can delete a range of cells without deleting the entire rows.


When I step through the code, each time I come to the line highlighted in red below, I get the following message: Run-time error '1004': Application-defined or object-defined error".


Is there a way to do this?

Code:
Sub PrepPasteWorksheets()
Worksheets("Processed Resources").Activate
    Dim r As Integer
    r = Worksheets("Processed Resources").Range("B8").Value
    daRange = "E9:BN" & CStr(r)
    Worksheets("Processed Resources").Range(daRange).Select[COLOR=#ff0000]
    Range(daRange).Delete Shift:=xlToUp[/COLOR]
Worksheets("Project Rep Data").Activate
    Dim rr As Integer
    rr = Worksheets("Project Rep Data").Range("B8").Value
    daRange = "E8:E" & CStr(rr - 1)
    Worksheets("Project Rep Data").Range(daRange).Select
    Selection.Copy
Worksheets("Processed Resources").Range("E8").ActiveCell
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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