PC Review


Reply
Thread Tools Rate Thread

Autofill to last cell in other column

 
 
Alex
Guest
Posts: n/a
 
      16th Dec 2008
How can I autofill the selected cell down in the selected column to the last
cell in the column to the right? I'd also like to exclude cells where the
cell to the right is null. Thank you very much.
 
Reply With Quote
 
 
 
 
John Howard
Guest
Posts: n/a
 
      16th Dec 2008
Hi Alex,

Assuming that you want to create the autofill programatically, rather than
manualy, the macro below should give you what you want, except the exluding
of null cells.

The only way to effect such an exlusion would be to delete the null rows
before the autofill.

Sub FillToLastRow()

Dim LastRow As Long
Dim FillRange As String
Dim FillColumn As Long


'###### Firstly Select the item you want to copy in the autofill column
'then run this macro

'Determines the column number of rhe selcted cell
FillColumn = ActiveCell.Column

'Determines the last used row in the
'first column to the right of the selected
'autofill column
LastRow = Cells(Rows.Count, FillColumn + 1).End(xlUp).Row

'Creates the autofill range address in string format
FillRange = Range(Cells(ActiveCell.Row, FillColumn), _
Cells(LastRow, FillColumn)).Address

'Autofills the selected column
'to the last row number, determined
'from the next column to the right
ActiveCell.AutoFill Destination:=Range(FillRange)

End Sub


--
Regards
John Howard
Sydney, Australia


"Alex" wrote:

> How can I autofill the selected cell down in the selected column to the last
> cell in the column to the right? I'd also like to exclude cells where the
> cell to the right is null. Thank you very much.

 
Reply With Quote
 
Alex
Guest
Posts: n/a
 
      17th Dec 2008
This is perfect! Thank you so much.

"John Howard" wrote:

> Hi Alex,
>
> Assuming that you want to create the autofill programatically, rather than
> manualy, the macro below should give you what you want, except the exluding
> of null cells.
>
> The only way to effect such an exlusion would be to delete the null rows
> before the autofill.
>
> Sub FillToLastRow()
>
> Dim LastRow As Long
> Dim FillRange As String
> Dim FillColumn As Long
>
>
> '###### Firstly Select the item you want to copy in the autofill column
> 'then run this macro
>
> 'Determines the column number of rhe selcted cell
> FillColumn = ActiveCell.Column
>
> 'Determines the last used row in the
> 'first column to the right of the selected
> 'autofill column
> LastRow = Cells(Rows.Count, FillColumn + 1).End(xlUp).Row
>
> 'Creates the autofill range address in string format
> FillRange = Range(Cells(ActiveCell.Row, FillColumn), _
> Cells(LastRow, FillColumn)).Address
>
> 'Autofills the selected column
> 'to the last row number, determined
> 'from the next column to the right
> ActiveCell.AutoFill Destination:=Range(FillRange)
>
> End Sub
>
>
> --
> Regards
> John Howard
> Sydney, Australia
>
>
> "Alex" wrote:
>
> > How can I autofill the selected cell down in the selected column to the last
> > cell in the column to the right? I'd also like to exclude cells where the
> > cell to the right is null. Thank you very much.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill column from data (code) in column next to it Matt Microsoft Excel Worksheet Functions 4 24th Apr 2009 06:17 PM
RE: Automating to autofill column B based on column A entry Shane Devenshire Microsoft Excel Misc 0 2nd Dec 2008 10:02 PM
VBA to autofill next blank cell in same column =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 8 28th Sep 2007 05:12 PM
Identify Last Cell and autofill last column =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 4 27th Sep 2007 03:02 AM
autoFill column equal to adjacent column Paulg Microsoft Excel Programming 4 17th Jul 2006 01:04 PM


Features
 

Advertising
 

Newsgroups
 


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