438 error when trying to put data into a separate workbook

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.

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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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