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

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Autofill in VBA question

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" wrote in message ...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Autofill in VBA question



"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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Autofill in VBA question

one way:

Sub test()
Dim lRow As Long
lRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastC ell).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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Autofill in VBA question

Thanks Ron, You are a Prince.

It works perfectly.


"Ron de Bruin" wrote in message
...
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" wrote in message
...
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
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 darksides Excel Programming 1 August 16th 06 04:03 PM
Autofill question lob Excel Worksheet Functions 2 February 17th 05 04:07 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
Autofill question Eric Dreshfield Excel Programming 3 September 3rd 03 02:10 PM


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

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

About Us

"It's about Microsoft Excel"