VBA to delete then copy/paste cells when there's something in column A

Bob L

New Member
Joined
May 10, 2020
Messages
36
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm looking for a way to delete everything below row 7 (except column A), then copy/paste B4:D7 each time there's something in column A and then copy/paste it values.

So, in the example below, delete everything below row 7 (except column A), copy/paste B4:D7 to B9 and B16 (because there's something in cells A9 and A16) and then copy/paste value everything below row 7. I need to be able to change the sheet name and the cells reference B4:D7 in the VBA.

Thanks.

Book1
ABCD
1
2
3
4A123
5789
67877
7455
8
9B
10
11
12
13
14
15
16C
Sheet1
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
Ok, how about
VBA Code:
Sub BobL()
   Dim StartRw As Long
   
   StartRw = 279
   With ActiveSheet
      .Range("E" & StartRw & ":AX" & Rows.Count).Clear
      .Range("E133:AX278").Copy .Range("A" & StartRw & ":A" & Rows.Count).SpecialCells(xlConstants).Offset(, 4)
      With .Range("E" & StartRw, .Range("E" & Rows.Count).End(xlUp).Offset(, 45))
         .Value = .Value
      End With
   End With
End Sub
 
Solution

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Bob L

New Member
Joined
May 10, 2020
Messages
36
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Ok, how about
VBA Code:
Sub BobL()
   Dim StartRw As Long
  
   StartRw = 279
   With ActiveSheet
      .Range("E" & StartRw & ":AX" & Rows.Count).Clear
      .Range("E133:AX278").Copy .Range("A" & StartRw & ":A" & Rows.Count).SpecialCells(xlConstants).Offset(, 4)
      With .Range("E" & StartRw, .Range("E" & Rows.Count).End(xlUp).Offset(, 45))
         .Value = .Value
      End With
   End With
End Sub
Yes, it works perfectly!! Thank you very much! :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,549
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,594
Messages
5,625,693
Members
416,127
Latest member
MALEPINZON

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
Top