ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro - Modular fill function (https://www.excelbanter.com/excel-programming/333758-macro-modular-fill-function.html)

Chaz

Macro - Modular fill function
 
I have created a number of macros in excel. One of them uses a function that
i would like to fill down a column for as many rows as there are in the
worksheet (which will vary from time to time). I was wondering if anyone
might have a suggestion how to code this.

Thanks

Duncan_J

Macro - Modular fill function
 
Hi Chaz, Try this...

Sub Autofill_Range()

Dim LastRow As Long
Dim LastCol As Long
Dim rng As Range

With ActiveSheet
Set rng = .UsedRange 'try to reset lastused cell
With rng
LastRow = .Rows(.Rows.Count).Row
LastCol = .Columns(.Columns.Count).Column
End With
' Change F1 to whatever your last column is
.Range("F1").AutoFill _
Destination:=.Range("F1:F" & LastRow), Type:=xlFillDefault
' Change th above to whatever last column you have Like Y:Y
End With
'
End Sub


"Chaz" wrote:

I have created a number of macros in excel. One of them uses a function that
i would like to fill down a column for as many rows as there are in the
worksheet (which will vary from time to time). I was wondering if anyone
might have a suggestion how to code this.

Thanks


havocdragon

Macro - Modular fill function
 
Im assuming you mean that the number of rows varies, as to how many rows
contain information correct? If thats true then this will work

Range("Where ever your info starts here").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Formula = "whatever you want to fill down"
Selection.FillDown

the only catch to this, is if there are blank bits of data somewhere, it
will stop at those instead.

"Chaz" wrote:

I have created a number of macros in excel. One of them uses a function that
i would like to fill down a column for as many rows as there are in the
worksheet (which will vary from time to time). I was wondering if anyone
might have a suggestion how to code this.

Thanks


Tushar Mehta

Macro - Modular fill function
 
Beyond the macro recorder (specifically, example 4)
http://www.tushar-
mehta.com/excel/vba/beyond_the_macro_recorder/index.htm

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I have created a number of macros in excel. One of them uses a function that
i would like to fill down a column for as many rows as there are in the
worksheet (which will vary from time to time). I was wondering if anyone
might have a suggestion how to code this.

Thanks



All times are GMT +1. The time now is 03:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com