Autofill problem

B

Barkomatic

I've got a macro that will take the value in the previous cell and
extend the series to the adjacent cells. Unfortunately, it isn't
acting in quite the way I had planned. The number of cells to be
filled is variable. For instance, a year will be entered into cell
L125 and should be extended thru to T125. The next row might have a
year entered in P126 and should be extended thru T126. So the end
point is always the same. Only the starting point varies. Here is
the code I have for the macro so far:

ActiveCell.Offset(0, -1).Range("A1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:I1"),
Type:=_xlFillSeries
ActiveCell.Range("A1:I1").Select


So how do I tell it to always end in Row T no matter where it starts?
 
J

JLGWhiz

If you preset your fill range so that it specifies column T as the end of the
range it should work.

Sub atofl()
ActiveCell.Offset(0, -1).Range("A1").Select
Set FillRange = Range(Cells(ActiveCell.Row, ActiveCell.Column), _
Cells(ActiveCell.Row, "T"))
Selection.AutoFill Destination:=FillRange, Type:=xlFillSeries
ActiveCell.Range("A1:I1").Select
End Sub
 
B

Barkomatic

ActiveCell.Offset(0, -1).Range("A1").Select
Set FillRange = Range(Cells(ActiveCell.Row, ActiveCell.Column), _
Cells(ActiveCell.Row, "T"))
Selection.AutoFill Destination:=FillRange, Type:=xlFillSeries
ActiveCell.Range("A1:I1").Select


Thanks! That worked like a charm. I appreciate the quick response,
too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top