Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

How to input data from another workbook using button

0

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
appExcel.Quit
End Sub

Answer
Discuss

Discussion

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: 1989) 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