PC Review


Reply
Thread Tools Rate Thread

Autofill variable range

 
 
Basta1980
Guest
Posts: n/a
 
      19th Mar 2008
Hi,

I try to wright a command which autofills a range adjacent to information in
the cells left. So if Range A1:A300 contains data and I have a formule in cel
B1 I normally double click the fill-handle to copy (or autofill) the formula
down to cel B300 (which is adjacent to cel A300). The below statement helps
me manage to automatically autofill the range (B1:B300). My problem is that
range A can be variable, so this time it's up to cel A300, the following time
it's up to cel A500. How should i adjust the statement?!

Sub test()
'
' test Macro
' Macro recorded 19-03-2008 by dresses
'

'
Range("B1").Select
Selection.AutoFill Destination:=Range("B1:B316")
Range("B1:B316").Select
End Sub
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      19th Mar 2008
various ways -

With ActiveSheet.Range("B1")
.AutoFill .Offset(0, -1).CurrentRegion.Columns(2)
End With

The above would only work correctly if A1 was in the top row of its
CurrentRegion, which in this case it must be as A1 is clearly the top row.

If that can't be guaranteed here's another way

Sub Test2
Dim rng As Range
Set rng = ActiveSheet.Range("B2")

rng.AutoFill Range(rng, rng.Offset(0, -1).End(xlDown).Offset(0, 1))

End Sub

BTW, no need to 'select' cells

Regards,
Peter T



"Basta1980" <(E-Mail Removed)> wrote in message
news:3DACB69C-D262-478C-9032-(E-Mail Removed)...
> Hi,
>
> I try to wright a command which autofills a range adjacent to information

in
> the cells left. So if Range A1:A300 contains data and I have a formule in

cel
> B1 I normally double click the fill-handle to copy (or autofill) the

formula
> down to cel B300 (which is adjacent to cel A300). The below statement

helps
> me manage to automatically autofill the range (B1:B300). My problem is

that
> range A can be variable, so this time it's up to cel A300, the following

time
> it's up to cel A500. How should i adjust the statement?!
>
> Sub test()
> '
> ' test Macro
> ' Macro recorded 19-03-2008 by dresses
> '
>
> '
> Range("B1").Select
> Selection.AutoFill Destination:=Range("B1:B316")
> Range("B1:B316").Select
> End Sub



 
Reply With Quote
 
Basta1980
Guest
Posts: n/a
 
      19th Mar 2008
Peter T,

Thnx for the tip. Sub Test 2 did the trick!

Regards

Basta1980

"Peter T" wrote:

> various ways -
>
> With ActiveSheet.Range("B1")
> .AutoFill .Offset(0, -1).CurrentRegion.Columns(2)
> End With
>
> The above would only work correctly if A1 was in the top row of its
> CurrentRegion, which in this case it must be as A1 is clearly the top row.
>
> If that can't be guaranteed here's another way
>
> Sub Test2
> Dim rng As Range
> Set rng = ActiveSheet.Range("B2")
>
> rng.AutoFill Range(rng, rng.Offset(0, -1).End(xlDown).Offset(0, 1))
>
> End Sub
>
> BTW, no need to 'select' cells
>
> Regards,
> Peter T
>
>
>
> "Basta1980" <(E-Mail Removed)> wrote in message
> news:3DACB69C-D262-478C-9032-(E-Mail Removed)...
> > Hi,
> >
> > I try to wright a command which autofills a range adjacent to information

> in
> > the cells left. So if Range A1:A300 contains data and I have a formule in

> cel
> > B1 I normally double click the fill-handle to copy (or autofill) the

> formula
> > down to cel B300 (which is adjacent to cel A300). The below statement

> helps
> > me manage to automatically autofill the range (B1:B300). My problem is

> that
> > range A can be variable, so this time it's up to cel A300, the following

> time
> > it's up to cel A500. How should i adjust the statement?!
> >
> > Sub test()
> > '
> > ' test Macro
> > ' Macro recorded 19-03-2008 by dresses
> > '
> >
> > '
> > Range("B1").Select
> > Selection.AutoFill Destination:=Range("B1:B316")
> > Range("B1:B316").Select
> > End Sub

>
>
>

 
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 down until reach variable range tpeter Microsoft Excel Programming 3 23rd Oct 2009 05:23 PM
Autofill with Column as a variable LuisE Microsoft Excel Programming 5 17th Aug 2008 09:00 AM
variable column numbers for autofill mattybinv Microsoft Excel Programming 1 8th Dec 2005 01:06 PM
Variable Autofill range Kate Microsoft Excel Programming 2 23rd Feb 2004 09:20 PM
Variable Autofill Range Kate Microsoft Excel Programming 1 23rd Feb 2004 09:12 PM


Features
 

Advertising
 

Newsgroups
 


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