Paste and fill down

Mugalh01

New Member
Joined
Mar 23, 2018
Messages
15
Hiya,
I am a novice in VBA (this is day 2) and wanted to write a script to copy some values from sheet to another and fill down to the last filled row. This is what I have so far:

Dim lRow As Long


lRow = Worksheets("Data").Cells(Worksheets("Data").Rows.Count, "A").End(xlUp).Row


lRow = lRow + 1


Worksheets("Summary").Select
Range("A12:G19").Copy
Worksheets("Data").Select
Range("A" & lRow).PasteSpecial xlPasteValues
Worksheets("Summary").Select
Range("A4").Copy
Worksheets("Data").Range("H" & lRow).PasteSpecial xlPasteValues

Its the value in column H that I want to paste/fill down to the last filled row but I'm getting no joy.
Tried this - ActiveCell.AutoFill ActiveCell.Resize(Lastrow - ActiveCell.Row + 1) from a different thread as well as
ActiveCell.AutoFill Destination:=Range(ActiveCell, Cells(Cells(Rows.Count, "B").End(xlUp).Row, "C"))
but no joy - the last one partly worked but the number in column H was increasing incrementally. I wanted it to remain the same.

Help please
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
try this
Code:
Dim lastrowF As Long
Range("H2").Select
lastrowF = Range("A" & Rows.count).End(xlUp).row
ActiveCell.AutoFill Range(ActiveCell.Address, Cells(lastrowF, ActiveCell.Column))
 
Upvote 0
Heres another way which should work for you:

Code:
Dim lRow As Long, rng As Range, rng2 As Range

Set rng = Sheets("Summary").Range("A12:G19")
Set rng2 = Sheets("Summary").Range("A4")

With Sheets("Data")
    lRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
    .Range(.Cells(lRow, "A"), .Cells(lRow + rng.Rows.Count - 1, "G")).Value = rng.Value
    .Range(.Cells(lRow, "H"), .Cells(lRow + rng.Rows.Count - 1, "H")).Value = rng2.Value
End With
 
Upvote 0
Thanks for your response.
However, I've tried the code and the autofill function is still not working. I'm not getting any errors, just not filling down. this is all of it compiled

Sub find_last_row()


Dim lRow As Long
Dim lastrowF As Long


lRow = Worksheets("Data").Cells(Worksheets("Data").Rows.Count, "A").End(xlUp).Row
lastrowF = Range("A" & Rows.Count).End(xlUp).Row
lRow = lRow + 1


Worksheets("Summary").Select
Range("A12:G19").Copy
Worksheets("Data").Select
Range("A" & lRow).PasteSpecial xlPasteValues
Worksheets("Summary").Select
Range("A4").Copy
Worksheets("Data").Range("H" & lRow).PasteSpecial xlPasteValues
Range("H2").Select
ActiveCell.AutoFill Range(ActiveCell.Address, Cells(lastrowF, ActiveCell.Column))


End Sub
 
Upvote 0
Works like a charm boss. I don't understand it yet (i'll try to decipher it) but it's all good, thank you.
On to the next obstacle :)
 
Upvote 0
ps. that was Steve's code that i was referring to.
don't know yet how to respond to individual responses
 
Upvote 0

Forum statistics

Threads
1,216,021
Messages
6,128,319
Members
449,440
Latest member
Gillian McGovern

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