copy and paste using offset vba

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
Code:
Sub Move_CenterANDDepart()


 Dim rng As Range, cell As Range, del As Range
 Set rng = Intersect(Range("C:C"), ActiveSheet.UsedRange)
 For Each cell In rng
   If (cell.Value) = "Valid" _
 Then
       If del Is Nothing Then
          Set del = cell
       Else: Set del = Union(del, cell)
       End If
    End If
 Next cell
 On Error Resume Next
 del.Offset(-4).Copy
 del.Offset(2, -2).PasteSpecial

What this code does is find Valid and copy 4 up cells and paste 2 down and 2 left from cells that contains Valid.
However seems like copying works, but paste does not work at all.

Do you guys have any idea?

thank you
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If del is multiple non-contiguous cells, you can't do a single copy/paste. In that case if you comment out the On Error Resume Next line, you will get an error message. Since you are looping through each cell in column C you could do the copy/paste on each found cell individually.
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,858
Members
449,194
Latest member
HellScout

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