VBA: Fill Columns until Blank Cell in Another Column

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I have my code below. I need to "auto fill" my formulas in cells H2:P2 down until it hits the first blank row. Unfortunately, the code I'm using will auto fill until the last row used in the sheet. I have inserted a blank row between data where I would need the code to stop. I have it referencing column G currently.

Any tips?

Here is my code. I have 2 that I've been playing around with:
Dim lastrow As Long
lastrow = Range("G" & rows.Count).End(xlUp).Row
Range("H2:P2").AutoFill Destination:=Range("H2:P" & lastrow), Type:=xlFillDefault

and the other one:
With Sheets("Code")
.Range("H2:P2").AutoFill .Range("H2:P" & .Cells(.rows.Count, "G").End(xlUp).Row)
End With
 
You're code was looking from the bottom of the upwards for a non blank cell, whereas using xlDown it's going the other way & will stop just before the first blank
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You're code was looking from the bottom of the upwards for a non blank cell, whereas using xlDown it's going the other way & will stop just before the first blank
Thank you for taking the time to explain it to me and thank you for all your help!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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