-1

and thank you in advance for looking at/taking a crack at my question. Let me preface this with the fact that I am extremely new to VBA.

I am trying to set up a double loop, the first of which will copy a set number of cells (A3:K3) in the first workbook, and paste them into specific cells on a seperate workbook, then save the workbook as the value in (L3), then close that second workbook.

The second loop (if possible) will tell the macro to repeat the first loop, within the same range on the next row (A4:K4), and repeat until the cell (A(x), where x=first empty cell)

Most of my copy paste stuff was done by hand, and after extensive research, I've leared that .select is the devil. My first loop seemed to work fine, but due to inefficiencies of manually manipulating the code, I've crashed every time.

Please help me to eliminate the inefficiencies of my code, which is as follows:

Dim J As Integer
Do
For J = 3 To Last_Row_In_Column_A
Workbooks.Open FileName:= _
"Desktop\Term Workbook Template.xlsx"
Windows("NBV Forecast.xlsm").Activate
Cells(J, 1).Select
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C4").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 2).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C5").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 3).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C6").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 4).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C7").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 5).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C9").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 6).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C10").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 7).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C14").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 8).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C15").Select
Application.CutCopyMode = False
Selection.Copy
Application.CutCopyMode = False
Windows("NBV Forecast.xlsm").Activate
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 9).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("C18").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 10).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("G18").Select
Selection.End(xlUp).Select
Selection.End(xlUp).Select
Selection.End(xlUp).Select
Selection.End(xlUp).Select
Selection.End(xlUp).Select
Range("G5").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 11).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Term Workbook Template.xlsx").Activate
Range("G11").Select
ActiveSheet.Paste
Windows("NBV Forecast.xlsm").Activate
Cells(J, 12).Select
Dim Path As String
Dim FileName As String
Path = "Desktop\"
FileName = Range("L12")
Windows("Term Workbook Template.xlsx").Activate
ActiveWorkbook.SaveAs FileName:=Path & FileName & ".xlsx"
ActiveWorkbook.Close
Next J
Loop

End Sub

.... I know this is more than likely a mess, and I apologize for any inconvenience here. I would appreciate any help that I can get!

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271

1 Answers1

0

if you examine your underlying problem it is basically a duplicate of this question, you should find you answer in one form or another here

Copy from one workbook and paste into another

https://stackoverflow.com/a/19352099/6868389

Community
  • 1
  • 1
lllpratll
  • 368
  • 1
  • 3
  • 8