Please Help with Macro

C

Carlie

I would like to create this macro to:

1.Select and clear data (A4:last row) from several sheets in a template
workbook.
3.Open master workbook(6 in total)
2.Select and copy a specific range (A10:last row -1) from master
workbook.
3.Paste range into relevant template sheets starting from A4.
4.Select columns Y:Z in template and format with %
5.Write functions in cells Y5:Z5
6.Drag and drop to last row

This is what I've done so far but it does'nt work properly. I would
also like to repeat steps 3-6 above for all master workbooks.

Thanks in advance

Sub CopyPastedata()

Dim myLastRow As Long
Dim myLastColumn As Long
Dim WksT As Worksheet

Set WksT = Workbooks("templates.xls").Worksheet("sheet1", "sheet2",
_
"sheet3", "sheet3", "sheet4", "sheet5", "sheet6")

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastcell = Cells(myLastRow, myLastColumn).Address
myrange = "A4:" & myLastcell
myformula = "Y5:Z5:" & myLastcell

WksT(myrange).Clear

'Open master1 Workbook
Workbooks.Open Filename:="C:pathname.csv"

'Find,select and copy A10 to last row minus 1

'activate template workbook and paste
Windows(templates).Activate
Range(myrange).PasteSpecial

Columns("Y:Z").Select
Selection.NumberFormat = "0.00%"
Range("Y5").Select
ActiveCell.FormulaR1C1 = "=RC[-19]/R4C[-19]"
Range(myformula).FillDown
Range("Z5").Select
ActiveCell.FormulaR1C1 = "=RC[-10]/R4C[-10]"
'filldown to mylastcell
Range(myformula).FillDown
Windows("master1.csv").Close
ActiveWorkbook.Save

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top