ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autofill (https://www.excelbanter.com/excel-programming/359942-autofill.html)

Coal Miner

Autofill
 
Is there a way to modify this code with some 'autofill' in order to copy the
formula down that is located in Column C and D?

Sub test()
Dim InsertionPoint As Range, rg As Range
Dim colToCheck As String
Dim expandBy As Long
Dim wsh As Worksheet
Set wsh = ActiveSheet
colToCheck = "A"
expandBy = 25
'Find last currently used row in column colToCheck
Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1,
0).EntireRow

'Insert rows
Set rg = InsertionPoint.Resize(expandBy)
rg.Insert


Bernie Deitrick

Autofill
 
Try this version:

Sub test()
Dim InsertionPoint As Range, rg As Range
Dim colToCheck As String
Dim expandBy As Long
Dim wsh As Worksheet
Dim StartRow As Long

Set wsh = ActiveSheet
colToCheck = "A"
expandBy = 25
'Find last currently used row in column colToCheck
Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1, 0).EntireRow
StartRow = InsertionPoint.Row - 1

'Insert rows
Set rg = InsertionPoint.Resize(expandBy)
rg.Insert

Range("C" & StartRow).Resize(1, 2).Copy _
Range("C" & StartRow).Resize(expandBy + 1, 2)

End Sub

HTH,
Bernie
MS Excel MVP


"Coal Miner" wrote in message
...
Is there a way to modify this code with some 'autofill' in order to copy the
formula down that is located in Column C and D?

Sub test()
Dim InsertionPoint As Range, rg As Range
Dim colToCheck As String
Dim expandBy As Long
Dim wsh As Worksheet
Set wsh = ActiveSheet
colToCheck = "A"
expandBy = 25
'Find last currently used row in column colToCheck
Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1,
0).EntireRow

'Insert rows
Set rg = InsertionPoint.Resize(expandBy)
rg.Insert




Coal Miner

Autofill
 
Thanks so much Bernie. Have a good day!!! :)

"Bernie Deitrick" wrote:

Try this version:

Sub test()
Dim InsertionPoint As Range, rg As Range
Dim colToCheck As String
Dim expandBy As Long
Dim wsh As Worksheet
Dim StartRow As Long

Set wsh = ActiveSheet
colToCheck = "A"
expandBy = 25
'Find last currently used row in column colToCheck
Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1, 0).EntireRow
StartRow = InsertionPoint.Row - 1

'Insert rows
Set rg = InsertionPoint.Resize(expandBy)
rg.Insert

Range("C" & StartRow).Resize(1, 2).Copy _
Range("C" & StartRow).Resize(expandBy + 1, 2)

End Sub

HTH,
Bernie
MS Excel MVP


"Coal Miner" wrote in message
...
Is there a way to modify this code with some 'autofill' in order to copy the
formula down that is located in Column C and D?

Sub test()
Dim InsertionPoint As Range, rg As Range
Dim colToCheck As String
Dim expandBy As Long
Dim wsh As Worksheet
Set wsh = ActiveSheet
colToCheck = "A"
expandBy = 25
'Find last currently used row in column colToCheck
Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1,
0).EntireRow

'Insert rows
Set rg = InsertionPoint.Resize(expandBy)
rg.Insert





Bernie Deitrick

Autofill
 
Thanks so much Bernie. Have a good day!!! :)

You're welcome.... and I will, thanks - I'm heading home in 15 minutes 8-)

Bernie




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

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