Prev: Run-time error '380'
Next: Error on Code
From: LaDdIe on 15 Feb 2010 15:16 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
From: OssieMac on 15 Feb 2010 20:39 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") -- Regards, OssieMac
From: LaDdIe on 16 Feb 2010 05:39 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. "OssieMac" wrote: > 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") > > > -- > Regards, > > OssieMac > >
From: OssieMac on 16 Feb 2010 06:01 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) -- Regards, OssieMac
From: OssieMac on 16 Feb 2010 06:12
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) -- Regards, OssieMac |