Copying formats, then formulas down to dynamic last row not working

rossross

New Member
Joined
Apr 11, 2022
Messages
39
Office Version
  1. 365
Platform
  1. Windows
What I'm attempting to do: copy all the rows from an open workbook, insert them into my other workbook that is a template, between to placeholders with formulas. my data in the template goes from A:CE. I've got the first part working where I insert the rows, but I don't know how to paste formats and formulas to a row where I don't always know the final number. Sometimes it's row 405 sometimes it's row 49850.

VBA Code:
Sub StripData()

Dim myWb As Workbook
Dim myRowsToCopy As Range


Set myWb = Workbooks.Open("C:\Users\User\Desktop\Practice\Data_Pull_Dummy.xlsx")

With myWb.Sheets("Data").Range("A:XFD")
    Set myRowsToCopy = Range(.Cells(.Rows.Count, 1).End(xlUp), .Cells(2, .Columns.Count))
End With

myRowsToCopy.Copy
Workbooks("Template.xlsm").Worksheets("Raw").Range("3:3").Insert Shift:=xlDown
Application.CutCopyMode = False

Dim lastrow As Range
Set lastrow = Workbooks("Template.xlsm").Worksheets("Raw").Cells(Rows.Count, 1).End(xlUp).Offset(1)

Workbooks("Template.xlsm").Worksheets("Raw").Range("B2:CE2").Copy

Do Until WorksheetFunction.CountA(lastrow.EntireRow) = 0
    Workbooks("Template.xlsm").Worksheets("Raw").Range("B3:CE3").End(xlDown).PasteSpecial Paste:=xlPasteFormats
    Set lastrow = lastrow.Offset(1)
    Application.CutCopyMode = False

Loop

End Sub


As far as I can tell, this last part is pretty useless. That's what I've managed to gather across the internet. I need to copy the formats in B2:CE2 down to the final row, then I need to copy the actual formulas in AK2:CE2 down to the last row, then I need to delete my dummy row that was used in Row 2 and the last row that was previously a placeholder in row 3. Full disclosure - i have no idea what i'm really doing.

Any help is appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,814
Messages
6,181,120
Members
453,021
Latest member
Justyna P

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