ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autofill Destination (https://www.excelbanter.com/excel-programming/305713-autofill-destination.html)

poppy

Autofill Destination
 
Hi

I am trying to fill a number of cells with months up to the curren
month without having to hardcode the months. My problem is in the re
line. I would appreciate all your help.


Code
-------------------
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
lastrow = lastrow + 3

For i = 2 To 2
For j = lastrow To lastrow
With Cells((j), (i))
.FormulaR1C1 = "Jan"
Cells(j, i).Select
Selection.AutoFill Destination:=Range("B14:H14"), Type:=xlFillDefault
End With
Next
Nex
-------------------


Kind regard

--
Message posted from http://www.ExcelForum.com


Norman Jones

Autofill Destination
 
Hi Poppy,

Try changing:

Selection.AutoFill Destination:=Range("B14:H14"),
Type:=xlFillDefault
To

.AutoFill Destination:=Selection.Resize(12), Type:=xlFillDefault

Note the initial period.


---
Regards,
Norman



"poppy " wrote in message
...
Hi

I am trying to fill a number of cells with months up to the current
month without having to hardcode the months. My problem is in the red
line. I would appreciate all your help.


Code:
--------------------
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
lastrow = lastrow + 3

For i = 2 To 2
For j = lastrow To lastrow
With Cells((j), (i))
.FormulaR1C1 = "Jan"
Cells(j, i).Select
Selection.AutoFill Destination:=Range("B14:H14"), Type:=xlFillDefault
End With
Next
Next
--------------------


Kind regards


---
Message posted from http://www.ExcelForum.com/




Norman Jones

Autofill Destination
 
Hi Poppy,

To add, it is rarely necessary to make a selection, so this portion of your
code:

With Cells((j), (i))
.FormulaR1C1 = "Jan"
Cells(j, i).Select
Selection.AutoFill Destination:=Range("B14:H14"), Type:=xlFillDefault
End With


could be written as:

With Cells((j), (i))
.FormulaR1C1 = "Jan"
.AutoFill Destination:=.Resize(12), Type:=xlFillDefault
End With


---
Regards,
Norman



poppy

Autofill Destination
 
Hi Norman

The code works fine except for one small detail. It fills down. How d
I make it go in the other direction. In other words fill across rathe
downwards.


Thanx

Kind Regard

--
Message posted from http://www.ExcelForum.com


Norman Jones

Autofill Destination
 
Hi Poppy,

Replace:

Resize(12)

with

Resize(,12)

---
Regards,
Norman


"poppy " wrote in message
...
Hi Norman

The code works fine except for one small detail. It fills down. How do
I make it go in the other direction. In other words fill across rather
downwards.


Thanx

Kind Regards


---
Message posted from http://www.ExcelForum.com/




poppy

Autofill Destination
 
Thanx Norman

I really appreciate all your help.


Kind Regard

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 04:11 AM.

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