RensselaerPower
New Member
- Joined
- Feb 22, 2016
- Messages
- 1
I'm trying to create a macro that will open a separate workbook and use the variables from the source workbook and put them into the destination workbook.
I'm able to open the other workbook, but when I try to put the data in that workbook I get a 438 error. Here is my code:
Also, the other workbook I'm trying to open at the end I have to put data into that as well. I couldn't get that code to work with the first workbook so I changed the code to what I'm using in the "currentyearpath" if that helps find the problem.
Thanks for any help.
I'm able to open the other workbook, but when I try to put the data in that workbook I get a 438 error. Here is my code:
Also, the other workbook I'm trying to open at the end I have to put data into that as well. I couldn't get that code to work with the first workbook so I changed the code to what I'm using in the "currentyearpath" if that helps find the problem.
Thanks for any help.
Code:
Workbooks.Open currentyearpath
Windows(currentyearfile).Visible = False
ActiveSheet(1).Range("B5") = grossold
ActiveSheet(1).Range("C5") = netold
ActiveSheet(1).Range("D5") = dieselold
ActiveSheet(1).Range("G5") = daytotal
ActiveSheet(1).Range("J5") = 1000
ActiveSheet(2).Range("B5") = gross14
ActiveSheet(2).Range("C5") = net14
ActiveSheet(2).Range("D5") = diesel14
ActiveSheet(2).Range("G5") = day14
ActiveSheet(3).Range("B5") = gross14
ActiveSheet(3).Range("C5") = net14
ActiveSheet(3).Range("D5") = gasbegin14
ActiveSheet(3).Range("E5") = gasend14
ActiveSheet(3).Range("J5") = day14
ActiveSheet(4).Range("B5") = gross15
ActiveSheet(4).Range("C5") = net15
ActiveSheet(4).Range("D5") = gasbegin15
ActiveSheet(4).Range("E5") = gasend15
ActiveSheet(4).Range("J5") = day15
Workbooks(currentyearfile).Close SaveChanges = True
With appxl
.Workbooks.Open airfilepath
.Visible = False
End With
Set myfile = appxl.Windows(airfilename)
myfile.Activate
lastrow = 0
Set currentSheet = appxl.Sheets(1)
With currentSheet
lastrow = .Cells(.Rows.Count, "C").End(xlUp).row
End With
lastrow = lastrow + 1
currentSheet.Cells(lastrow, 3) = gastotal
currentSheet.Cells(lastrow, 4) = dieseltotal
appxl.Workbooks(airfilename).Close SaveChagnes = True
End Sub