ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   telling a macro to go back to where it came from (https://www.excelbanter.com/excel-programming/386992-telling-macro-go-back-where-came.html)

[email protected]

telling a macro to go back to where it came from
 
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


Barb Reinhardt

telling a macro to go back to where it came from
 
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



" wrote:

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



jayray

telling a macro to go back to where it came from
 
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




On Apr 6, 3:17 pm, wrote:
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





All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com