Copying Down Cells - With, VBA

Fredek

Board Regular
Joined
Mar 8, 2011
Messages
65
Hi guys,

I have the below code to copy down cells up to the level of adjacent column. I have a couple of questions;,
  1. If I run the macro multiple times I get excess data cells at the bottom. Do I need to add an if statement to stop the copying of cells if it is already level with column to the left?
  2. Is there a neat way of combining the two With statements into one?

Thank you!

Code:
With Range("C" & Rows.Count).End(xlUp)
    Range(.Offset(1, 0), Range("C" & Range("B" & Rows.Count).End(xlUp).Row)) = .Value
End With
With Range("D" & Rows.Count).End(xlUp)
    Range(.Offset(1, 0), Range("D" & Range("C" & Rows.Count).End(xlUp).Row)) = .Value
End With
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try
Code:
With Range("C" & Rows.Count).End(xlUp)
    .Resize(Range("B" & Rows.Count).End(xlUp).Row - .Row + 1).FillDown
End With
With Range("D" & Rows.Count).End(xlUp)
    .Resize(Range("C" & Rows.Count).End(xlUp).Row - .Row + 1).FillDown
End With
 
Upvote 0

Forum statistics

Threads
1,225,757
Messages
6,186,848
Members
453,379
Latest member
gabriellegonzalez

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