Autofill with Range Names

Deborah Holt

New Member
Joined
Jul 2, 2018
Messages
4
I have a worksheet where I want to autofill the fields in rows 4 to 8from the last populated column, into the next column.
Rows 4 to 8 will always be ‘fixed’.
Currently, the last populated column is BA.


I can establish the LastCol & NextCol variables but I can’t passthem to my AutoFill command successfully.
Basically, I want to replace the ‘hard-coded’ BA & BB columns withtheir variable values LastCol & NextCol.

Any help much appreciated – code below

Sub LastColumnInOneRow()
'Find the last used column in a Row: row 4 in this example
Sheets("Book").Select
Dim LastCol As Integer
With ActiveSheet
LastCol = .Cells(4,.Columns.Count).End(xlToLeft).Column
End With

Dim NextCol As Integer
NextCol = LastCol + 1
End Sub


Sub newmonth_book()
'
' newmonth_book Macro
'
Sheets("Book").Select
Dim selection1 As Range
Dim selection2 As Range


Set selection1 =Range("BA4:BA8")
Set selection2 = Range("BA4:BB8")

selection1.AutoFillDestination:=selection2, Type:=xlFillDefault
End Sub


 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
is the below what you are looking to do?

Code:
Sub hardcode()
Dim lc As Long, nc As Long, ws As Worksheet
Set ws = ThisWorkbook.Sheets("Book")


With ws
Let lc = .Cells(4, .Columns.Count).End(xlToLeft).Column
Let nc = lc + 1


.Range(.Cells(4, nc), .Cells(8, nc)).Value = .Range(.Cells(4, lc), .Cells(8, lc)).Value




End With
End Sub
 
Upvote 0
Sort of, however, your code is just copying the values where as I want to autofill, keeping the formatting and changing the monthname.
Here is the Range BA4 to BA8 that I'm trying to drag to the next column.

Apr-18
123,723
41.73%
38.56%
89.31
<colgroup><col width="109" style="width: 82pt; mso-width-source: userset; mso-width-alt: 3986;"> <tbody> </tbody>

Rows 5 to 8 contain formulae.
Many thanks for your help so far
 
Upvote 0
Hi BarryL I’ve re-read your reply and I think if I just replace the ‘Value’ parts with ‘Autofill’ parts then that should do the trick.
I”ll have another go tomorrow
Many thanks again
 
Upvote 0
Hi Deborah,

understood, can you try the below?

Code:
Sub hardcode()
Dim lc As Long, nc As Long, ws As Worksheet
Set ws = ThisWorkbook.Sheets("Book")




With ws
    Let lc = .Cells(4, .Columns.Count).End(xlToLeft).Column
    Let nc = lc + 1
    .Range(.Cells(4, lc), .Cells(8, lc)).AutoFill Destination:=.Range(.Cells(4, lc), .Cells(8, nc)), Type:=xlFillDefault
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,849
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top