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

Bob L

New Member
Joined
May 10, 2020
Messages
44
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
 
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
 
Upvote 0
Solution

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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! :)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

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