telling a macro to go back to where it came from

G

ghamilton

How can I modify this so that Excel will go back to the workbook it
came from? This macro goes from "company financials" over to my macro
sheet "Formatting Macros.xls". I want to use it for others like
"Division 1.xls" and "Division 2.xls", etc. so I need some way of
telling it to just go back to where it started. Please help.

Windows("FORMATTING MACROS.xls").Activate
Application.Run Range("ScOnWindow")
Range("N6").Select
Selection.Copy
Windows("COMPANY FINANCIALS.xls").Activate
Application.Run Range("ScOnWindow")
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
 
G

Guest

TRy adding this

Dim aWB as workbook

Set aWB = activeworkbook 'Put this at the beginning

When you want to return to the original workbook, put

awb.activate
 
J

jayray

Add this:

Dim MySheet as string
Dim MyCell as string

At the beginning of your macro, add:

MySheet=activesheet.name
MyCell=activecell.address

[your macro here...]

At the end of your macro add
Sheets(MySheet).activate
Range(MyCell).select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top