PC Review


Reply
Thread Tools Rate Thread

Autofill in VBA question

 
 
CarlosAntenna
Guest
Posts: n/a
 
      12th Apr 2007
I am not a VBA programmer by any stretch of the imagination. I am here to
ask for help with a macro that I _recorded_.

Part of what my macro does is:

Insert a column in a sheet of data
Type a formula into the top cell of the new column
Copy the formula down the column for as far as there is data

I did this last step by double clicking the fill handle and this is the code
that is generated

Range("B4").Select
Selection.AutoFill Destination:=Range("B4:B450")
Range("B4:B450").Select

That's OK this time, but what about when there is more or less lines of
data.

How can this be changed to accomplish what I am looking for?

Thanks,
Carlos


 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      12th Apr 2007
Hi Carlos

Try this

Will fill B1 till the row of the last cell with data in A

Sub test2()
Dim LastRow As Long
With Worksheets("Sheet1")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("B1").AutoFill Destination:=.Range("B1:B" & LastRow) _
, Type:=xlFillDefault
End With
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"CarlosAntenna" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>I am not a VBA programmer by any stretch of the imagination. I am here to
> ask for help with a macro that I _recorded_.
>
> Part of what my macro does is:
>
> Insert a column in a sheet of data
> Type a formula into the top cell of the new column
> Copy the formula down the column for as far as there is data
>
> I did this last step by double clicking the fill handle and this is the code
> that is generated
>
> Range("B4").Select
> Selection.AutoFill Destination:=Range("B4:B450")
> Range("B4:B450").Select
>
> That's OK this time, but what about when there is more or less lines of
> data.
>
> How can this be changed to accomplish what I am looking for?
>
> Thanks,
> Carlos
>
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      12th Apr 2007


"CarlosAntenna" wrote:

> I am not a VBA programmer by any stretch of the imagination. I am here to
> ask for help with a macro that I _recorded_.
>
> Part of what my macro does is:
>
> Insert a column in a sheet of data
> Type a formula into the top cell of the new column
> Copy the formula down the column for as far as there is data
>
> I did this last step by double clicking the fill handle and this is the code
> that is generated
>
> Range("B4").Select
> Selection.AutoFill Destination:=Range("B4:B450")
> Range("B4:B450").Select
>
> That's OK this time, but what about when there is more or less lines of
> data.
>
> How can this be changed to accomplish what I am looking for?
>
> Thanks,
> Carlos
>
>
>

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      12th Apr 2007
one way:

Sub test()
Dim lRow As Long
lRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
Range("B4:B" & lRow).FillDown
End Sub



--
Hope that helps.

Vergel Adriano


"CarlosAntenna" wrote:

> I am not a VBA programmer by any stretch of the imagination. I am here to
> ask for help with a macro that I _recorded_.
>
> Part of what my macro does is:
>
> Insert a column in a sheet of data
> Type a formula into the top cell of the new column
> Copy the formula down the column for as far as there is data
>
> I did this last step by double clicking the fill handle and this is the code
> that is generated
>
> Range("B4").Select
> Selection.AutoFill Destination:=Range("B4:B450")
> Range("B4:B450").Select
>
> That's OK this time, but what about when there is more or less lines of
> data.
>
> How can this be changed to accomplish what I am looking for?
>
> Thanks,
> Carlos
>
>
>

 
Reply With Quote
 
CarlosAntenna
Guest
Posts: n/a
 
      12th Apr 2007
Thanks Ron, You are a Prince.

It works perfectly.


"Ron de Bruin" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi Carlos
>
> Try this
>
> Will fill B1 till the row of the last cell with data in A
>
> Sub test2()
> Dim LastRow As Long
> With Worksheets("Sheet1")
> LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
> .Range("B1").AutoFill Destination:=.Range("B1:B" & LastRow) _
> , Type:=xlFillDefault
> End With
> End Sub
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "CarlosAntenna" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I am not a VBA programmer by any stretch of the imagination. I am here to
>>ask for help with a macro that I _recorded_.
>>
>> Part of what my macro does is:
>>
>> Insert a column in a sheet of data
>> Type a formula into the top cell of the new column
>> Copy the formula down the column for as far as there is data
>>
>> I did this last step by double clicking the fill handle and this is the
>> code that is generated
>>
>> Range("B4").Select
>> Selection.AutoFill Destination:=Range("B4:B450")
>> Range("B4:B450").Select
>>
>> That's OK this time, but what about when there is more or less lines of
>> data.
>>
>> How can this be changed to accomplish what I am looking for?
>>
>> Thanks,
>> Carlos



 
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 Question James8309 Microsoft Excel Worksheet Functions 0 24th Aug 2008 10:43 AM
Autofill Question =?Utf-8?B?U2NvdHQgSg==?= Microsoft Excel Programming 4 11th Jun 2007 09:47 PM
New autofill question =?Utf-8?B?Um9n?= Microsoft Access 4 22nd Jun 2006 01:25 PM
autofill question steely via AccessMonster.com Microsoft Access Forms 2 10th May 2005 09:39 PM
Q. Autofill question: Can I autofill alpha characters like I can numbers? George Microsoft Excel Programming 5 7th Aug 2004 10:33 AM


Features
 

Advertising
 

Newsgroups
 


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