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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Jeffrey Smith

Well-known Member
Joined
Feb 11, 2005
Messages
795
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
 

Exelinus

New Member
Joined
May 11, 2011
Messages
2
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
 

Watch MrExcel Video

Forum statistics

Threads
1,099,253
Messages
5,467,562
Members
406,543
Latest member
semoredhawk

This Week's Hot Topics

Top