Making fill-down formula conditional

RaydenUK

Board Regular
Joined
Mar 25, 2014
Messages
74
I have been using the fill-down code below and it works perfect if there is more than 2 rows that it is filling down. However, sometimes I only have 1 or 2 rows and it ends up filling down to the last cell possible in excel. How can I make this formula conditional to correct this?


Code:
    Range("L4").Select
    ActiveCell.Offset(0, -1).Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(0, 1).Select
    Range(Selection, Selection.End(xlUp)).Select
    Selection.FillDown
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi RaydenUK,

Your code seems to flip flop between Columns "L" and "K", but in my testing it only Autofilled Column "L". That being said, let me know how this works for you. It is easily adjusted to include more columns and how many rows you actually want to Autofil.

Please be sure to test this code on a backup copy of your work. This code is going to write data to your sheet!

Code:
Sub autofil_What()

    Dim sht As Worksheet
    Dim LastRow As Long
    
    LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
    Range("L4").AutoFill Range("L4:L" & LastRow)
    
End Sub

HTH

igold
 
Upvote 0
This almost works but I have borders around the entire page and it fills to the the last row with a border. How can I avoid this?
 
Upvote 0
Again, I am a little vague in exactly where the borders are, but see if this does what you are asking.

Code:
Sub af_What()

    Dim sht As Worksheet
    Dim LastRow As Long
    
    LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
    Range("L4").AutoFill Range("L4:L" & LastRow)
    Range("L4:L" & LastRow).Borders.LineStyle = xlNone
    
End Sub

igold
 
Last edited:
Upvote 0

Forum statistics

Threads
1,211,963
Messages
6,105,114
Members
447,947
Latest member
OX_2005

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