Selection autofill

L

LaDdIe

Hi,

Can I please have some help with the following code.

Range("A4").Select
Selection.AutoFill Destination:=Range("A5", (("NETDAYS"))).Value

NETDAYS is a named range that for demo purposes holds a value of "A20", so
the range to fill is A5:NETDAYS.

But something is wrong that I can't figure out.

Thanks
 
O

OssieMac

Firstly the AutoFill destination range starts on the same range as the cell
that holds the first value. In this case A4. Following should do the trick.

Range("A4").Select
Selection.AutoFill Destination:=Range("A4:NETDAYS")

However, it is not necessary to actually select. The following code is the
better method.

Range("A4").AutoFill Destination:=Range("A4:NETDAYS")
 
L

LaDdIe

Thanks for that reply OssieMac,

The named range NETDAYS is not actually at cell A20, but holds the value
A20, so what I need is an indirect reference to whatever value NETDAYS holds,
which could change to say A25 based on a calulation elsewhere.

Sorry if this was not made clear earlier.
 
O

OssieMac

Try the following. Note that a space and underscore at the end of a line is a
line break in an otherwise single line of code.

Using Selection method.

Range("A4").Select
Selection.AutoFill _
Destination:=Range(Selection, _
Range("NETDAYS").Value)


Alternative method.
Range("A4").AutoFill _
Destination:=Range("A4:" & _
Range("NETDAYS").Value)
 
O

OssieMac

Another option instead of using the colon and concatenating the range, a
comma can be used between the start and end ranges. (Similar to the Selection
example.)

Range("A4").AutoFill _
Destination:=Range("A4", _
Range("NETDAYS").Value)
 
L

LaDdIe

Once again thank you for your assitance,

I have tried all combinations of code and keeping getting this error:
Run-time error 1004
Method 'range' of object'_Global failed.

Would you be able to shed some light.
 
Top