ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   AutoFill Macro (https://www.excelbanter.com/excel-programming/370872-autofill-macro.html)

[email protected]

AutoFill Macro
 
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard


Ron de Bruin

AutoFill Macro
 
Use it like this for B1 in Sheet1
Note: it overwrite the data that is in B2:B ?

Sub test2()
Dim LastRow As Long
With Worksheets("Sheet1")
LastRow = .Cells(Rows.Count, "B").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



wrote in message ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard




Joergen Bondesen

AutoFill Macro
 
Hi Richard

Try below, please.

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row

Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard




Don Guillett

AutoFill Macro
 
try

br = Cells(Rows.Count, "b").End(xlUp).Row
Cells(1, "b").autofill Destination:=Range(Cells(1, "b"), Cells(br, "b"))

--
Don Guillett
SalesAid Software

wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard




[email protected]

AutoFill Macro
 
I tried the one:

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub

And I get the following error message:

Autofill method of range class failed.

When I tried:

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

I get the same message, what am I missing?

Thank you.

Richard
Joergen Bondesen wrote:
Hi Richard

Try below, please.

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row

Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard



Ron de Bruin

AutoFill Macro
 
You have only data in B1 of the sheet named Sheet1

LastRow = .Cells(Rows.Count, "B").End(xlUp).Row

This also find B1 now


--
Regards Ron de Bruin
http://www.rondebruin.nl



wrote in message ups.com...
I tried the one:

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub

And I get the following error message:

Autofill method of range class failed.

When I tried:

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

I get the same message, what am I missing?

Thank you.

Richard
Joergen Bondesen wrote:
Hi Richard

Try below, please.

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row

Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard





[email protected]

AutoFill Macro
 
Ron,

Not clear on your last message, my macro reads:

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

Since my data is only in B1, that is what I want to autofill from, I am
missing something basic, what is it?

Ron de Bruin wrote:
You have only data in B1 of the sheet named Sheet1

LastRow = .Cells(Rows.Count, "B").End(xlUp).Row

This also find B1 now


--
Regards Ron de Bruin
http://www.rondebruin.nl



wrote in message ups.com...
I tried the one:

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub

And I get the following error message:

Autofill method of range class failed.

When I tried:

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

I get the same message, what am I missing?

Thank you.

Richard
Joergen Bondesen wrote:
Hi Richard

Try below, please.

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row

Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard




Ron de Bruin

AutoFill Macro
 
Hi

Since my data is only in B1, that is what I want to autofill from, I am
missing something basic, what is it?


The code is looking for the last row with data in column B
LastRow = .Cells(Rows.Count, "B").End(xlUp).Row


It use that row now to AutoFill

.Range("B1").AutoFill Destination:=.Range("B1:B" & LastRow) _
, Type:=xlFillDefault


If you only have data in B1 it try to AutoFill B1 to B1 (error)

You can use another column to look for the last row
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

Or if you know the last row use that in the code

Sub test2()
Dim LastRow As Long
With Worksheets("Sheet1")
LastRow = 20
.Range("B1").AutoFill Destination:=.Range("B1:B" & LastRow) _
, Type:=xlFillDefault
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl



wrote in message oups.com...
Ron,

Not clear on your last message, my macro reads:

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

Since my data is only in B1, that is what I want to autofill from, I am
missing something basic, what is it?

Ron de Bruin wrote:
You have only data in B1 of the sheet named Sheet1

LastRow = .Cells(Rows.Count, "B").End(xlUp).Row

This also find B1 now


--
Regards Ron de Bruin
http://www.rondebruin.nl



wrote in message ups.com...
I tried the one:

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub

And I get the following error message:

Autofill method of range class failed.

When I tried:

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

I get the same message, what am I missing?

Thank you.

Richard
Joergen Bondesen wrote:
Hi Richard

Try below, please.

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row

Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard






Joergen Bondesen

AutoFill Macro
 
Hi Richard

Sorry about my bad programming.
I hope below will suits you better. 8-)


Option Explicit

Const Startcell As String = "B1"
Const SheetName As String = "Test1"

'----------------------------------------------------------
' Procedure : FillDown
' Date : 20060819
' Author : Joergen Bondesen
' Modifyed by :
' Purpose : Fill down Startcell to lastrow if Startcell
' < empty.
' Note : Change Const: 'Startcell' and 'SheetName'
'----------------------------------------------------------
'
Sub FillDown()

Dim WS As Worksheet
Dim Srange As Range
Dim Lastrow As Long

Set WS = Worksheets(SheetName)
Set Srange = WS.Range(Startcell)

With WS
'// Empty Startcell
If Srange = vbNullString Then End

'// Lastrow
Lastrow = .Cells(.Rows.Count, _
Srange.Column).End(xlUp).Row
'// Startrow = Lastrow
If Lastrow = Srange.Row Then End

'// Fill down
.Range(Startcell).AutoFill _
Destination:=.Range(.Cells(Srange.Row, _
Srange.Column), _
.Cells(Lastrow, Srange.Column))
End With

Set WS = Nothing
Set Srange = Nothing
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I tried the one:

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub

And I get the following error message:

Autofill method of range class failed.

When I tried:

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

I get the same message, what am I missing?

Thank you.

Richard
Joergen Bondesen wrote:
Hi Richard

Try below, please.

Sub test2()

Dim endRow As Long
endRow = Cells(Rows.Count, 2).End(xlUp).Row

Range("B1").Autofill Destination:=Range("B1:B" & endRow)
End Sub


--
Best regards
Joergen Bondesen


wrote in message
ups.com...
I thought that i posted this yesterday but I can't find the posting so
if this is a double post, please point me in the direction of the
original post and I will go from there.

I have the following Code:

Sub Autofill()
'
'
Range("B1").Select
Selection.Copy
Selection.AutoFill Destination:=Range("B1:B10")
Range("B1:B10").Select
Range("G17").Select
End Sub

I looked at previous postings on this group and found this topic
addressed before and I found code on how to do this so I attempted to
apply the following code:

Sub Test()
'
' Test Macro
'
Range("B1").Select
Dim endRow As Long
endRow = Cells(Rows.Count, ("B1:B")).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("B1:B")
End Sub

However, it keeps errorring out, any suggestions?

Thank you.

Richard






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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com