How to input data from another workbook using button


i have a problem. i have a workbook that contains database. i wanna calculate the averages of this database into new workbook. i was using record macro for make a button "input" in my workbook (database) and i wanna they show in my new workbook. this is my code that i make. can you correct my code and give me a solution for this? i need your help. thanks

Sub summary()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim wb As Workbook
Dim appExcel As Application
'create new excel application object
Set appExcel = New Application

'set the applications visible property to false
appExcel.Visible = False

Set wb = appExcel.Workbooks.Open("E:\tiga.xlsm")
Set ws1 = wb.Sheets(1)
Set ws2 = ThisWorkbook.Sheets(1)
With ws1
.Range("A3:A10").Formula = ws2.Range("D14")
.Range("B3:B10").Formula = "=AVERAGE($E$14:$E$30)"
.Range("C3:C10").Formula = "=AVERAGE($F$14:$F$30)"
.Range("D3:D10").Formula = "=AVERAGE($G$14:$G$30)"
.Range("E3:E10").Formula = "=AVERAGE($J$14:$J$30)"
.Range("F3:F10").Formula = "=AVERAGE($O$14:$O$30)"
End With

wb.Close SaveChanges:=False
End Sub



You are going to have to explain in GREAT DETAIL what data you are trying to copy exactly because your macro doesn't look like it has anything to do with the files you uploaded. This is a really simple problem to solve, so Update your original question with the extra detail and then let me know in a comment when you do that.
don (rep: 1959) Aug 3, '16 at 2:47 pm
Add to Discussion

Answer the Question

You must create an account to use the forum. Create an Account or Login