Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default AutoFill question

I'm trying to autofill to the cells to the right to keep the dates going when
entering new data with a macro every month. So without a macro I would
normally select the two cells (e.g. A1 and B1) with the previous two month
headers in them and autofill to the right so that it gives me the next month.
How can I do this in a macro when the cells are changing every time? I can
get to the point of where the two cells are highlighted but need to know how
to autofill. I thought that it would be something like this:

Selection.AutoFill Destination:=Selection.Offset(0, 1), Type:=xlFillDefault
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default AutoFill question

This is how to do it if you have selected the 2 cells:

Sub Autofill1()
Selection.AutoFill Destination:=Range _
(Selection, Selection.Offset(0, 1).End(xlDown).Offset(0, -1))
End Sub


And this is how to do it if you don't want to select the two cells (assumes that column A is
otherwise blank)

Sub Autofill2()
Dim myR As Range
Set myR = Cells(Rows.Count, 1).End(xlUp).Offset(-1, 0).Resize(2, 1)

On Error Resume Next
myR.AutoFill Destination:=Range _
(myR, myR.Offset(0, 1).End(xlDown).Offset(0, -1))

End Sub


HTH,
Bernie
MS Excel MVP


"carl" wrote in message
...
I'm trying to autofill to the cells to the right to keep the dates going when
entering new data with a macro every month. So without a macro I would
normally select the two cells (e.g. A1 and B1) with the previous two month
headers in them and autofill to the right so that it gives me the next month.
How can I do this in a macro when the cells are changing every time? I can
get to the point of where the two cells are highlighted but need to know how
to autofill. I thought that it would be something like this:

Selection.AutoFill Destination:=Selection.Offset(0, 1), Type:=xlFillDefault



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default AutoFill question

Hi Bernie,

Sorry for the confusion. I wanted to autofill to the right. So effectively
just right fill. But only one cell and not right until the end. It's
basically something that needs done once a month. So if I have Jan in cell
A1 and Feb in cell B1 then the next time the macro is run I want it to put
Mar in the next cell. But I need it to right fill taking the lead from the
previous cells rather than just have script that puts dates that you have
requested.

Thanks

Carl

"Bernie Deitrick" wrote:

This is how to do it if you have selected the 2 cells:

Sub Autofill1()
Selection.AutoFill Destination:=Range _
(Selection, Selection.Offset(0, 1).End(xlDown).Offset(0, -1))
End Sub


And this is how to do it if you don't want to select the two cells (assumes that column A is
otherwise blank)

Sub Autofill2()
Dim myR As Range
Set myR = Cells(Rows.Count, 1).End(xlUp).Offset(-1, 0).Resize(2, 1)

On Error Resume Next
myR.AutoFill Destination:=Range _
(myR, myR.Offset(0, 1).End(xlDown).Offset(0, -1))

End Sub


HTH,
Bernie
MS Excel MVP


"carl" wrote in message
...
I'm trying to autofill to the cells to the right to keep the dates going when
entering new data with a macro every month. So without a macro I would
normally select the two cells (e.g. A1 and B1) with the previous two month
headers in them and autofill to the right so that it gives me the next month.
How can I do this in a macro when the cells are changing every time? I can
get to the point of where the two cells are highlighted but need to know how
to autofill. I thought that it would be something like this:

Selection.AutoFill Destination:=Selection.Offset(0, 1), Type:=xlFillDefault




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default AutoFill question

Carl,

I'm sorry, I was confused... I still haven't had my coffee....

Sub AF1()
Selection.AutoFill Destination:=Range _
(Selection, Selection.Resize(1, 3))
End Sub

OR

Sub AF2()
Dim myR As Range
Set myR = Cells(1, Columns.Count). _
End(xlToLeft).Offset(0, -1).Resize(1, 2)

On Error Resume Next
myR.AutoFill Destination:=Range _
(myR, myR.Resize(1, 3))

End Sub


will work.

Bernie
MS Excel MVP


--
HTH,
Bernie
MS Excel MVP


"carl" wrote in message
...
Hi Bernie,

Sorry for the confusion. I wanted to autofill to the right. So effectively
just right fill. But only one cell and not right until the end. It's
basically something that needs done once a month. So if I have Jan in cell
A1 and Feb in cell B1 then the next time the macro is run I want it to put
Mar in the next cell. But I need it to right fill taking the lead from the
previous cells rather than just have script that puts dates that you have
requested.

Thanks

Carl

"Bernie Deitrick" wrote:

This is how to do it if you have selected the 2 cells:

Sub Autofill1()
Selection.AutoFill Destination:=Range _
(Selection, Selection.Offset(0, 1).End(xlDown).Offset(0, -1))
End Sub


And this is how to do it if you don't want to select the two cells (assumes that column A is
otherwise blank)

Sub Autofill2()
Dim myR As Range
Set myR = Cells(Rows.Count, 1).End(xlUp).Offset(-1, 0).Resize(2, 1)

On Error Resume Next
myR.AutoFill Destination:=Range _
(myR, myR.Offset(0, 1).End(xlDown).Offset(0, -1))

End Sub


HTH,
Bernie
MS Excel MVP


"carl" wrote in message
...
I'm trying to autofill to the cells to the right to keep the dates going when
entering new data with a macro every month. So without a macro I would
normally select the two cells (e.g. A1 and B1) with the previous two month
headers in them and autofill to the right so that it gives me the next month.
How can I do this in a macro when the cells are changing every time? I can
get to the point of where the two cells are highlighted but need to know how
to autofill. I thought that it would be something like this:

Selection.AutoFill Destination:=Selection.Offset(0, 1), Type:=xlFillDefault






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default AutoFill question

Perfect! Thanks!

"Bernie Deitrick" wrote:

Carl,

I'm sorry, I was confused... I still haven't had my coffee....

Sub AF1()
Selection.AutoFill Destination:=Range _
(Selection, Selection.Resize(1, 3))
End Sub

OR

Sub AF2()
Dim myR As Range
Set myR = Cells(1, Columns.Count). _
End(xlToLeft).Offset(0, -1).Resize(1, 2)

On Error Resume Next
myR.AutoFill Destination:=Range _
(myR, myR.Resize(1, 3))

End Sub


will work.

Bernie
MS Excel MVP


--
HTH,
Bernie
MS Excel MVP


"carl" wrote in message
...
Hi Bernie,

Sorry for the confusion. I wanted to autofill to the right. So effectively
just right fill. But only one cell and not right until the end. It's
basically something that needs done once a month. So if I have Jan in cell
A1 and Feb in cell B1 then the next time the macro is run I want it to put
Mar in the next cell. But I need it to right fill taking the lead from the
previous cells rather than just have script that puts dates that you have
requested.

Thanks

Carl

"Bernie Deitrick" wrote:

This is how to do it if you have selected the 2 cells:

Sub Autofill1()
Selection.AutoFill Destination:=Range _
(Selection, Selection.Offset(0, 1).End(xlDown).Offset(0, -1))
End Sub


And this is how to do it if you don't want to select the two cells (assumes that column A is
otherwise blank)

Sub Autofill2()
Dim myR As Range
Set myR = Cells(Rows.Count, 1).End(xlUp).Offset(-1, 0).Resize(2, 1)

On Error Resume Next
myR.AutoFill Destination:=Range _
(myR, myR.Offset(0, 1).End(xlDown).Offset(0, -1))

End Sub


HTH,
Bernie
MS Excel MVP


"carl" wrote in message
...
I'm trying to autofill to the cells to the right to keep the dates going when
entering new data with a macro every month. So without a macro I would
normally select the two cells (e.g. A1 and B1) with the previous two month
headers in them and autofill to the right so that it gives me the next month.
How can I do this in a macro when the cells are changing every time? I can
get to the point of where the two cells are highlighted but need to know how
to autofill. I thought that it would be something like this:

Selection.AutoFill Destination:=Selection.Offset(0, 1), Type:=xlFillDefault








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill Question Scott J[_2_] Excel Programming 4 June 11th 07 09:47 PM
Autofill in VBA question CarlosAntenna Excel Programming 4 April 12th 07 08:48 PM
Autofill question darksides Excel Programming 1 August 16th 06 04:03 PM
Q. Autofill question: Can I autofill alpha characters like I can numbers? George[_22_] Excel Programming 5 August 7th 04 10:33 AM
AutoFill Question nkob[_2_] Excel Programming 2 November 14th 03 08:56 PM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"