Activate other workbook

Exelinus

New Member
Joined
May 11, 2011
Messages
2
Hello,

After two days of googling (since om still a beginner) I have yet not found a solution to this (probably easy to solve) problem.
I will firstly try to explain the problem and afterward the whole idea of the solution (if anyone wants to comment).

I am trying to copy values from two sheets in an external workbook to a "Total" sheet in the same external workbook.
That is, I want to add the values from "A1"/Sheet 1 and "A1"/Sheet 2" to "A1"/Sheet "Total"

I tried using something like this:

Windows("import.xls").activate

However, even though the file import.xls is open, I get an error "Index is out of interval" (Translated but hopefully right).
I need to be able to switch back and forth between the opened workbooks but failed finding a way obviously, so hopefully someone here knows what command to use.

The goal:
I got x amount of files, all which are sent to my from different people.
All files have different numbers of sheets.
All sheets look the same though.
I want to add these matrices up to a total per person.
Once that is done, I want to add them up again with a "mega" total.
These totalts + the mega total should be stored in the master and easily be updated if the import files change.
The master also have a few graphs which uses the imported data.

The solution I am trying to build is:
Create a temp sheet within every importfile
Create the total
Copy the total over to the master
Close all importfiles
Create the mega total in the master.


Thanks
Linus
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Here's a starting point:

Code:
Sub GetValues()
  Dim WB1 As Workbook
 
  Set WB1 = Workbooks("Book1.xls")
 
 
  WB1.Sheets("Total").Range("A1") = WB1.Sheets("Sheet1").Range("A1").Value + WB1.Sheets("Sheet2").Range("A1").Value
 
End Sub

Let me know if this helps and you need more.

Jeff
 
Upvote 0
Thanx for the quick replies. I'll try both solutions when I'm back at work.

Feel free to comment on the pseudo code, it might not be the best solution but it is the best one I could think of. (I've managed to write most of the code but got stuck on this activate problem.).

/Linus
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

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