VBA: Fill Columns until Blank Cell in Another Column

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
73
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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
How about
VBA Code:
Range("H2:P2").AutoFill Destination:=Range("H2:P2").End(xlDown), Type:=xlFillDefault
 
Upvote 0
Oops, it should be
VBA Code:
Range("H2:P2").AutoFill Destination:=Range("H2:P2", Range("H2:P2").End(xlDown)), Type:=xlFillDefault
 
Upvote 0
Oops, it should be
VBA Code:
Range("H2:P2").AutoFill Destination:=Range("H2:P2", Range("H2:P2").End(xlDown)), Type:=xlFillDefault
Thanks for your help! It's still filling the formulas all the way to the bottom of the sheet and not stopping at the blank row.
 
Upvote 0
If you want to fill the formula down to the last used row in col G, then your code should do that.
 
Upvote 0
If you are trying to fill the formula down until the 1st blank cell in col G then try
VBA Code:
lastrow = Range("G2").End(xlDown).Row
 
Upvote 0
Solution
If you are trying to fill the formula down until the 1st blank cell in col G then try
VBA Code:
lastrow = Range("G2").End(xlDown).Row
You're the best!! It works perfect!

So the problem was is that I was referencing Column G and not specifically G2? Referencing the entire column would put me to the last row in the sheet, where as G2 would bring me down until the blank line?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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