Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill/FillDown in a dynamic range

Status
Not open for further replies.

as0125

Technical User
Jun 3, 2004
70
US
Hi, I'm trying to figure out how to autofill/filldown a range in which the number of rows may change periodically. I'm using a variable to store the number of rows counted, but don't know how to incorporate that variable into the autofill/filldown. Here is a sample of my code:

Range("K2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Dim totalrows As Integer
Dim f As Integer
totalrows = ActiveSheet.UsedRange.Rows.Count
f = totalrows - 2 'account for header/footer rows
Worksheets("Sheet1").Range("A2:J"f"").FillDown

Thanks for any help!
 
Replace this:
Worksheets("Sheet1").Range("A2:J"f"").FillDown
By this:
If f > 2 Then
Worksheets("Sheet1").Range("A2:J" & f).FillDown
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 

PHV,

Thank you! I didn't think about concatenation in this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top