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
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